Tôi mới phát triển Android và cũng có thể sử dụng chế độ xem danh sách có thể mở rộng lần đầu tiên. Tôi đang tạo một ứng dụng trong đó tôi nhận được tất cả nội dung của d listview có thể mở rộng từ webservice. Tôi nhận được tất cả các nội dung từ wevservice là tốt nhưng sau đó khi không có con của cha mẹ trong listview mở rộng các tùy chỉnh adapter merhod mở rộng listview getchildcount() trả về null và cung cấp cho một ngoại lệ con trỏ null như thế nào tôi có thể chỉ hiển thị phụ huynh trong danh sách với không có con và cả khi cả hai đều có sẵn?Chế độ xem danh sách mở rộng mà không cần trẻ em
Cảm ơn bạn
public View getChildView(int p_id, int c_id, boolean bln1, View view,ViewGroup viewgroup) {
// TODO Auto-generated method stub
if (view == null) {
view = inflater.inflate(com.example.eventlive.R.layout.homescreen_list_item_child, viewgroup,false);
}
TextView textView = (TextView) view.findViewById(R.id.list_item_text_child);
//"i" is the position of the parent/group in the list and
//"i1" is the position of the child
textView.setText(mParent.get(p_id).getArrayChildren().get(c_id));
view.setBackgroundResource(R.drawable.child_bg);
//return the entire view
return view;
}
//counts the number of children items so the list knows how many times calls getChildView() method
@Override
public int getChildrenCount(int p_id) {
// TODO Auto-generated method stub
return mParent.get(p_id).getArrayChildren().size();
}
gửi mã của bạn .. – Pragnani