Reputation: 64
I'm writing an application with an expandablelistview an a custom arrayList. My problem is that the expandablelistview doesn't show me the child items and I don't know where is the problem. The arrayList is coming from a class that I create for save same data in a database.
I post the code below:
public class CustomAdapterExpandable extends BaseExpandableListAdapter {
private Context c;
private ArrayList<Data> data;
private FireBaseReadData fireBaseReadData;
private DatabaseReference databaseReference;
private Preference preference = new Preference();
public CustomAdapterExpandable(Context ctx, ArrayList<Data> data) {
this.c = ctx;
this.data = data;
}
@Override
public int getGroupCount() {
return data.size();
}
@Override
public int getChildrenCount(int groupPosition) {
data.get(0).get(groupPosition);
return data.size();
}
@Override
public Object getGroup(int groupPosition) {
return data.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return data.get(groupPosition).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return data.get(0).get(groupPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return data.get(groupPosition).get(childPosition);
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
databaseReference = FirebaseDatabase.getInstance().getReference();
fireBaseReadData = new FireBaseReadData(databaseReference);
if(convertView == null){
convertView = LayoutInflater.from(c).inflate(R.layout.mainlayout, parent, false);
}
TextView name = (TextView) convertView.findViewById(R.id.TxT_text);
Button Btn_Reg = (Button) convertView.findViewById(R.id.Btn_ShowDialog);
final Data data = (Data) this.getGroup(groupPosition);
name.setText(data.getTournamentName());
Btn_Reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowDialog(groupPosition);
}
});
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final Data data = (Data) this.getChild(groupPosition, childPosition);
if(convertView == null){
convertView = LayoutInflater.from(c).inflate(R.layout.childlayout, parent, false);
}
TextView register = (TextView) convertView.findViewById(R.id.txt_reg);
TextView players = (TextView) convertView.findViewById(R.id.txt_players);
register.setText(data.getNumberOfPlayer());
players.setText(data.getNumberOfPlayer());
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Data class
public class Data {
String tournamentName;
String nameCreator;
int numberOfPlayer;
int playerAvailable;
String name_Player;
Data(){
}
/***********************************************/
private int getPlayerAvailable() {
return playerAvailable;
}
void setPlayerAvailable(int PlayerAvailable) {
playerAvailable = PlayerAvailable;
}
/***********************************************/
public int getNumberOfPlayer() {
return numberOfPlayer;
}
void setNumberOfPlayer(int numbPlayer) {
numberOfPlayer = numbPlayer;
}
/***********************************************/
public String getName_Player() {
return name_Player;
}
void setName_Player(String name_player) {
name_Player = name_player;
}
/***********************************************/
String getTournamentName() {
return tournamentName;
}
void setTournamentName(String NameTournament) {
tournamentName = NameTournament;
}
/***********************************************/
String getNameCreator() {
return nameCreator;
}
void setNameCreator(String Name) {
nameCreator = Name;
}
int get(int n){
return n;
}
}
Thanks for answers.
Upvotes: 0
Views: 36
Reputation: 89
you are not getting child size properly try this
@Override
public int getChildrenCount(int groupPosition) {
return groupList.get(groupPosition).getChild().size();
}
Group Class
public class Group {
String groupName;
int groupID;
ArrayList<Data>child=new ArrayList<Data>();
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public int getGroupID() {
return groupID;
}
public void setGroupID(int groupID) {
this.groupID = groupID;
}
public ArrayList<Data> getChild() {
return child;
}
public void setChild(ArrayList<Data> child) {
this.child = child;
}
}
then pass ArrayList Of Groups to your adapter
Upvotes: 1