Birçok öğretici ve SO'dan bazı hata sorularını takip ederek bir ExpandableListView hazırlıyorum. Üst liste, iki TextView ve standart düzen içeren bir ImageButton'dan oluşur. Çocuk listesi tek bir TextView'den oluşur. Veri kaynağı, etkinlikten SQLite Veritabanından gelir ve ArrayList'e oluşturulur.Android ExpandableListView getChildView tetiklemiyor
Sorun:
nasılsa üst grup listesi bile butonunun düzgün çalıştığını ama genişletmeye çalışırken, bu alışkanlık genişletmek normalde çalışır. Bu yüzden bazı Tost mesajı koymaya çalışıyorum ama etkinliği açtıktan sonra, Tost mesajı hiç gösterilmediği için tetiklemiyor getChildView()
yöntemine benziyor.
ExpandableListAdapter sınıfı Sana vermek Herhangi bir yardım için teşekkür ederiz bu
public class InventoryListExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<Inventory> data;
private HashMap<String, ArrayList<String>> list_data;
public InventoryListExpandableListAdapter(Context context, ArrayList<Inventory> data, HashMap<String, ArrayList<String>> list_data) {
this.context = context;
this.data = data;
this.list_data = list_data;
}
@Override
public int getGroupCount() {return data.size();}
@Override
public int getChildrenCount(int groupPosition) {return list_data.get(data.get(groupPosition)).size();}
@Override
public Inventory getGroup(int groupPosition) {return data.get(groupPosition);}
@Override
public Object getChild(int groupPosition, int childPosition) {return list_data.get(data.get(groupPosition).getCode()).get(childPosition);}
@Override
public long getGroupId(int groupPosition) {return groupPosition;}
@Override
public long getChildId(int groupPosition, int childPosition) {return childPosition;}
@Override
public boolean hasStableIds() {return true;}
@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
final Inventory inventory = getGroup(groupPosition);
convertView = View.inflate(context, R.layout.listview_layout_two_row_delete, null);
ImageButton btnDelete = (ImageButton)convertView.findViewById(R.id.btnDelete);
TextView text1 = (TextView)convertView.findViewById(R.id.text1);
TextView text2 = (TextView)convertView.findViewById(R.id.text2);
text1.setText(inventory.getCode());
text2.setText(inventory.getItem());
btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, "DELETED", Toast.LENGTH_SHORT).show();
}
});
}
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String)getChild(groupPosition, childPosition);
LayoutInflater infalInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = infalInflater.inflate(R.layout.listview_layout_single_text, null);
}
Toast.makeText(context, "Make Child number "+String.valueOf(childPosition), Toast.LENGTH_SHORT).show();
TextView text1 = (TextView)convertView.findViewById(R.id.text1);
text1.setText(childText);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
gibidir. Teşekkür ederim.
getChildrenCount' bunu kontrol ettim 0 – Blackbelt
dönüyor 'çünkü muhtemelen çağrılmaz ve büyüklüğü değil 0 – poring91