मैं एक एंड्रॉइड इंटरफ़ेस प्रोग्राम करने की कोशिश कर रहा हूं जो कि एक तरफ विस्तारणीय सूची और दूसरी तरफ एक टुकड़ा का उपयोग करता है ताकि मैं विस्तारणीय सूची के बच्चों पर क्लिक करके विभिन्न संसाधन लोड कर सकूं। लेकिन दुर्भाग्य से मुझे इस सूची के बारे में कहीं भी कोई अच्छा ट्यूटोरियल नहीं मिल रहा है। हां मैंने एपीआई डेमो में देखा है और मैंने बेसएक्सपैंडेबल लिस्ट एडाप्टर के साथ एक सामान्य सूची बनाई है लेकिन फिर भी, उन सूची को अच्छी तरह से समझना अच्छा है कि यह एक अच्छा ट्यूटोरियल के बिना कठिन है, क्या आपके पास कोई अच्छा या जानकारी है जिसे मैं देख सकता हूं?एंड्रॉइड एक्सपेंडेबल लिस्ट व्यू - एक ट्यूटोरियल की तलाश
उत्तर
देता है आप का अनुगमन करते हुए विस्तार योग्य सूची दृश्य के उदाहरण काम कर पा सकते हैं:
बच्चे पर क्लिक करने के लिए, आप इस तरह से संभाल सकते हैं।
getExpandableListView().setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// your code...
}
});
आशा है कि यह आपकी मदद करेगा। धन्यवाद ..
आइटम सूची बनाएं
List<ParentItem> itemList = new ArrayList<ParentItem>();
ParentItem parent1 = new ParentItem();
parent1.getChildItemList().add(new ChildItem());
parent1.getChildItemList().add(new ChildItem());
parent1.getChildItemList().add(new ChildItem());
ParentItem parent2 = new ParentItem();
parent2.getChildItemList().add(new ChildItem());
parent2.getChildItemList().add(new ChildItem());
parent2.getChildItemList().add(new ChildItem());
itemList.add(parent1);
itemList.add(parent2);
ExpandableListViewAdapter adapter = new ExpandableListViewAdapter(context, itemList);
डाटा ऑब्जेक्ट्स
public class ParentItem {
private List<ChildItem> childItemList;
public ParentItem() {
childItemList = new ArrayList<ChildItem>();
}
public List<ChildItem> getChildItemList() {
return childItemList;
}
}
public class ChildItem {
// filll with your data
}
एडाप्टर
public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
private static final class ViewHolder {
TextView textLabel;
}
private final List<ParentItem> itemList;
private final LayoutInflater inflater;
public ExpandableListViewAdapter(Context context, List<ParentItem> itemList) {
this.inflater = LayoutInflater.from(context);
this.itemList = itemList;
}
@Override
public ChildItem getChild(int groupPosition, int childPosition) {
return itemList.get(groupPosition).getChildItemList().get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public int getChildrenCount(int groupPosition) {
return itemList.get(groupPosition).getChildItemList().size();
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
final ViewGroup parent) {
View resultView = convertView;
ViewHolder holder;
if (resultView == null) {
resultView = inflater.inflate(android.R.layout.test_list_item, null); //TODO change layout id
holder = new ViewHolder();
holder.textLabel = (TextView) resultView.findViewById(android.R.id.title); //TODO change view id
resultView.setTag(holder);
} else {
holder = (ViewHolder) resultView.getTag();
}
final ChildItem item = getChild(groupPosition, childPosition);
holder.textLabel.setText(item.toString());
return resultView;
}
@Override
public ParentItem getGroup(int groupPosition) {
return itemList.get(groupPosition);
}
@Override
public int getGroupCount() {
return itemList.size();
}
@Override
public long getGroupId(final int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View theConvertView, ViewGroup parent) {
View resultView = theConvertView;
ViewHolder holder;
if (resultView == null) {
resultView = inflater.inflate(android.R.layout.test_list_item, null); //TODO change layout id
holder = new ViewHolder();
holder.textLabel = (TextView) resultView.findViewById(android.R.id.title); //TODO change view id
resultView.setTag(holder);
} else {
holder = (ViewHolder) resultView.getTag();
}
final ParentItem item = getGroup(groupPosition);
holder.textLabel.setText(item.toString());
return resultView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
आप
==============================
+Parent 1
==============================
-child 1.1
==============================
-child 1.2
==============================
-child 1.3
==============================
+Parent 2
==============================
-child 2.1
==============================
-child 2.2
==============================
-child 2.3
==============================
लेकिन, मैं सूचियों के बच्चों पर क्लिक ईवेंट कैसे संभाल सकता हूं? कारण यह है कि मैंने पाया है कि सभी ट्यूटोरियल के साथ मुख्य समस्या है – DeX03
'सेमी कॉलन (;) 'गायब'
मुझे शून्य' holder.textLabel.setText (item.toString() मिल रहा है); ', यह कैसे तय किया? –
इस तरह से आप की घटनाओं को संभाल कर सकते हैं:
getExpandableListView().setOnChildClickListener(new OnChildClickListener()
{
public boolean onChildClick(ExpandableListView parent,
View v, int groupPosition, int childPosition, long id)
{
// your code...
}
}
अप्रासंगिक उत्तर .... –
- 1. एक्सपेंडेबल लिस्ट व्यू एक्सपेंडेबल लिस्ट व्यू
- 2. एक्सपेंडेबल लिस्ट व्यू
- 3. एंड्रॉइड एक्सपेंडेबल लिस्ट व्यू और एसक्यूएलएट डाटाबेस
- 4. एंड्रॉइड एक्सपेंडेबल लिस्ट व्यू - कुछ समूह को गैर विस्तार योग्य
- 5. एंड्रॉइड एक्सपेंडेबल लिस्ट व्यू बटन के साथ माता-पिता
- 6. एंड्रॉइड लिस्ट व्यू
- 7. एंड्रॉइड लिस्ट व्यू -
- 8. एंड्रॉइड कस्टम लिस्ट व्यू
- 9. एंड्रॉइड लिस्ट व्यू एनीमेशन
- 10. एंड्रॉइड लिस्ट व्यू थीम
- 11. एंड्रॉइड लिस्ट व्यू रीफ्रेश
- 12. एंड्रॉइड लिस्ट व्यू हेडर
- 13. एंड्रॉइड लिस्ट व्यू
- 14. मैं एंड्रॉइड पर एक्सपेंडेबल लिस्ट व्यू के समूह सूचक की चौड़ाई कैसे प्राप्त कर सकता हूं?
- 15. एंड्रॉइड एक्सपेंडेबल सूची
- 16. एक विस्तारणीय लिस्ट व्यू
- 17. एक किनेक्ट ट्यूटोरियल की तलाश में
- 18. एंड्रॉइड लिस्ट व्यू लाइव अपडेट
- 19. एंड्रॉइड लिस्ट व्यू चयन हटाएं
- 20. एंड्रॉइड लिस्ट व्यू स्क्रॉलबार स्टाइल
- 21. एक्सपेंडेबल लिस्ट व्यू में समूह आइटम के अंदर एक बटन कैसे डालें?
- 22. लिस्ट व्यू
- 23. लिस्ट व्यू
- 24. विस्तारणीय लिस्ट व्यू
- 25. एंड्रॉइड कॉन्टेक्स्ट मेमोरी लीक लिस्ट व्यू AudioManager
- 26. विभाजक के साथ एंड्रॉइड लिस्ट व्यू
- 27. एंड्रॉइड लिस्ट व्यू चेकबॉक्स के साथ देखें:
- 28. एंड्रॉइड लिस्ट व्यू रीफ्रेश सिंगल रो
- 29. ऑनलाइन ओपनजीएल 3.1+ ट्यूटोरियल की तलाश में
- 30. एंड्रॉइड, कस्टम लिस्ट एडाप्टर टेक्स्ट व्यू-टेक्स्ट
मैं विश्वास नहीं कर सकता इस के रूप में "रचनात्मक नहीं" चिह्नित किया गया था! यह बहुत रचनात्मक था, और जवाब बहुत उपयोगी! इस प्रश्न को पोस्ट करने के लिए धन्यवाद, DeX03। –