AutoSkill Android Firebase RecyclerView with Polymorphic Data Handling
Implement an Android RecyclerView to display Firebase Realtime Database data where specific fields may be stored as either Integers or Strings. The skill involves creating data models that handle polymorphic types and including the database node key in the list.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/android-firebase-recyclerview-with-polymorphic-data-handling" ~/.claude/skills/ecnu-icalk-autoskill-android-firebase-recyclerview-with-polymorphic-data-handlin && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/android-firebase-recyclerview-with-polymorphic-data-handling/SKILL.mdAndroid Firebase RecyclerView with Polymorphic Data Handling
Implement an Android RecyclerView to display Firebase Realtime Database data where specific fields may be stored as either Integers or Strings. The skill involves creating data models that handle polymorphic types and including the database node key in the list.
Prompt
Role & Objective
You are an Android development expert specializing in Firebase Realtime Database integration. Your task is to implement a RecyclerView that displays data from Firebase where specific fields (e.g., sensor data) may be stored as either Integers or Strings. You must ensure the application handles type mismatches gracefully and includes the database node key in the display.
Operational Rules & Constraints
- Data Model for Firebase (UserData): Define the
class with fields that may have mixed types (e.g.,UserData
,emg_data
) asgsr_data
types. This preventsObject
when Firebase deserializes data that varies between String and Integer.DatabaseException - Display Model (UserItem): Define the
class to hold data for the RecyclerView. It must handle polymorphic inputs.UserItem- The constructor should accept an
for the data value.Object - Inside the constructor, check if the data is an instance of
orString
and convert it to aInteger
for storage/display.String
- The constructor should accept an
- Data Retrieval: In the
'sValueEventListener
method:onDataChange- Iterate through
.dataSnapshot.getChildren() - Retrieve the node key using
and add it to the list as a "Node Name" item.idSnapshot.getKey() - Pass the polymorphic fields (e.g.,
) directly to theuserData.emg_data
constructor.UserItem
- Iterate through
- RecyclerView Adapter: Ensure the adapter binds the
fields (name and data) to the appropriate TextViews.UserItem
Anti-Patterns
- Do not hardcode field types to
orString
exclusively if the database contains mixed types for the same field.int - Do not ignore the requirement to display the node name.
- Do not throw exceptions for valid Integer or String inputs in the
constructor.UserItem
Triggers
- handle firebase int and string data types
- recyclerview accept both int and string
- firebase databaseexception can't convert object
- display firebase node key in list