जवाबों:
यह कोशिश >>>
सभी वस्तुओं के लिए
getExpandableListView().setGroupIndicator(null);
Xml में
android:groupIndicator="@null"
android:groupIndicator
संपत्ति एक राज्य सक्षम drawable लेता है। यानी आप अलग-अलग राज्यों के लिए अलग-अलग इमेज सेट कर सकते हैं।
जब समूह में कोई संतान नहीं है, तो संबंधित राज्य 'State_empty' है
ये संदर्भ लिंक देखें:
के लिए state_empty
, आप एक अलग छवि सेट कर सकते हैं जो भ्रमित नहीं है, या, बस कुछ भी प्रदर्शित करने के लिए पारदर्शी रंग का उपयोग करें ...
अपने स्टेटफुल ड्राबल में इस आइटम को दूसरों के साथ जोड़ें ...।
<item android:state_empty="true" android:drawable="@android:color/transparent"/>
तो, आपका सांख्यिकीविद् इस तरह हो सकता है:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_empty="true" android:drawable="@android:color/transparent"/>
<item android:state_expanded="true" android:drawable="@drawable/my_icon_max" />
<item android:drawable="@drawable/my_icon_min" />
</selector>
यदि आप एक्सपेंडेबल लाइस्टऐक्टिविटी का उपयोग कर रहे हैं, तो आप इस प्रकार से ग्रुपइन्केटर को ऑनक्रिएट में सेट कर सकते हैं:
getExpandableListView().setGroupIndicator(getResources().getDrawable(R.drawable.my_group_statelist));
मैंने काम करने के लिए यह परीक्षण किया है।
StrayPointer के उत्तर और ब्लॉग के कोड के आधार पर, आप कोड को और भी सरल बना सकते हैं:
अपने xml में विस्तार योग्य सूची में फोलोइंग जोड़ें:
android:groupIndicator="@android:color/transparent"
फिर एडॉप्टर में आप निम्न कार्य करते हैं:
@Override
protected void bindGroupView(View view, Context paramContext, Cursor cursor, boolean paramBoolean){
**...**
if ( getChildrenCount( groupPosition ) == 0 ) {
indicator.setVisibility( View.INVISIBLE );
} else {
indicator.setVisibility( View.VISIBLE );
indicator.setImageResource( isExpanded ? R.drawable.list_group_expanded : R.drawable.list_group_closed );
}
}
SetImageResource विधि का उपयोग करके आप इसे एक-लाइनर के साथ पूरा करते हैं। आपको अपने एडाप्टर में तीन इंटेगर सरणियों की आवश्यकता नहीं है। आपको विस्तारित और ध्वस्त राज्य के लिए XML चयनकर्ता की भी आवश्यकता नहीं है। सभी जावा के माध्यम से किया जाता है।
साथ ही, यह दृष्टिकोण सही संकेतक भी दिखाता है जब एक समूह डिफ़ॉल्ट रूप से विस्तारित होता है जो ब्लॉग से कोड के साथ काम नहीं करता है।
getGroupView()
आपके BaseExpandableListAdapter
कार्यान्वयन की विधि में उपयोग करने के लिए है। इस उदाहरण के कार्यान्वयन पर एक नज़र डालें ।
ViewHolder
पैटर्न का उपयोग करता है। indicator
दृश्य धारक का चर नाम है।
जैसा कि एक अलग उत्तर में उल्लेख किया गया है, चूंकि एंड्रॉइड एक अन-एक्सपेंडेड लिस्ट ग्रुप को खाली मानता है, इसलिए आइकॉन को ड्रा नहीं किया जाता है, भले ही ग्रुप में बच्चे हों।
इस लिंक ने मेरे लिए समस्या हल कर दी: http://mylifewithandroid.blogspot.com/2011/06/hiding-group-indicator-for-empty-groups.html
मूल रूप से आपको डिफॉल्ट ड्रॉबल को पारदर्शी के रूप में सेट करना होगा, ड्रॉबल को इमेज व्यू के रूप में अपने ग्रुप व्यू में ले जाएं और अपने एडॉप्टर में इमेज को टॉगल करें।
अपने कोड में बस समूह सूची के लिए कस्टम एक्सएमएल का उपयोग करें और है कि में डाल imageView के लिए GroupIndicator ।
और नीचे दिए गए सरणियों को अपने एक्सपेंडेबल लाइस्ट एडेप्टर में जोड़ें
private static final int[] EMPTY_STATE_SET = {};
private static final int[] GROUP_EXPANDED_STATE_SET = { android.R.attr.state_expanded };
private static final int[][] GROUP_STATE_SETS = { EMPTY_STATE_SET, // 0
GROUP_EXPANDED_STATE_SET // 1
};
ExpandableListAdapter की विधि में भी नीचे के रूप में एक ही चीजें जोड़ें
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
{
if (convertView == null)
{
LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.row_group_list, null);
}
//Image view which you put in row_group_list.xml
View ind = convertView.findViewById(R.id.iv_navigation);
if (ind != null)
{
ImageView indicator = (ImageView) ind;
if (getChildrenCount(groupPosition) == 0)
{
indicator.setVisibility(View.INVISIBLE);
}
else
{
indicator.setVisibility(View.VISIBLE);
int stateSetIndex = (isExpanded ? 1 : 0);
Drawable drawable = indicator.getDrawable();
drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
}
}
return convertView;
}
संदर्भ: http://mylifewithandroid.blogspot.in/2011/06/hiding-group-indicator-for-empty-groups.html
XML में
android:groupIndicator="@null"
में ExpandableListAdapter
-> getGroupView
कोड के बाद कॉपी करें
if (this.mListDataChild.get(this.mListDataHeader.get(groupPosition)).size() > 0){
if (isExpanded) {
arrowicon.setImageResource(R.drawable.group_up);
} else {
arrowicon.setImageResource(R.drawable.group_down);
}
}
यह XML से एक और तरीका हो सकता है, सेट android:groupIndicator="@null"
संदर्भ लिंक: https://stackoverflow.com/a/5853520/2624806
आप मेरा समाधान सुझाएं:
1) डिफॉल्ट डिफॉल्ट ग्रुप इंडिकेटर:
<ExpandableListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="240dp"
android:layout_gravity="start"
android:background="#cccc"
android:groupIndicator="@android:color/transparent"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
/>
2) विस्तार योग्य एडाप्टर में:
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = new TextView(context);
}
((TextView) convertView).setText(groupItem.get(groupPosition));
((TextView) convertView).setHeight(groupHeight);
((TextView) convertView).setTextSize(groupTextSize);
//create groupIndicator using TextView drawable
if (getChildrenCount(groupPosition)>0) {
Drawable zzz ;
if (isExpanded) {
zzz = context.getResources().getDrawable(R.drawable.arrowup);
} else {
zzz = context.getResources().getDrawable(R.drawable.arrowdown);
}
zzz.setBounds(0, 0, groupHeight, groupHeight);
((TextView) convertView).setCompoundDrawables(null, null,zzz, null);
}
convertView.setTag(groupItem.get(groupPosition));
return convertView;
}
बस मिहिर त्रिवेदी के जवाब पर सुधार करना चाहते थे। आप इसे getGroupView () के अंदर रख सकते हैं जो MyExpandableListAdapter क्लास के अंदर है
View ind = convertView.findViewById(R.id.group_indicator);
View ind2 = convertView.findViewById(R.id.group_indicator2);
if (ind != null)
{
ImageView indicator = (ImageView) ind;
if (getChildrenCount(groupPosition) == 0)
{
indicator.setVisibility(View.INVISIBLE);
}
else
{
indicator.setVisibility(View.VISIBLE);
int stateSetIndex = (isExpanded ? 1 : 0);
/*toggles down button to change upwards when list has expanded*/
if(stateSetIndex == 1){
ind.setVisibility(View.INVISIBLE);
ind2.setVisibility(View.VISIBLE);
Drawable drawable = indicator.getDrawable();
drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
}
else if(stateSetIndex == 0){
ind.setVisibility(View.VISIBLE);
ind2.setVisibility(View.INVISIBLE);
Drawable drawable = indicator.getDrawable();
drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
}
}
}
... और लेआउट दृश्य के लिए, यह मेरा group_items.xml है
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/group_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:textSize="15sp"
android:textStyle="bold"/>
<ImageView
android:id="@+id/group_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/arrow_down_float"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingTop="20dp"/>
<ImageView
android:id="@+id/group_indicator2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/arrow_up_float"
android:layout_alignParentRight="true"
android:visibility="gone"
android:paddingRight="20dp"
android:paddingTop="20dp"/>
आशा है कि मदद करता है ... याद रखना छोड़ देना
यह प्रयोग करें यह पूरी तरह से मेरे लिए काम कर रहा है।
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/group_indicator_expanded" android:state_empty="false" android:state_expanded="true"/>
<item android:drawable="@drawable/group_indicator" android:state_empty="true"/>
<item android:drawable="@drawable/group_indicator"/>
</selector>
क्या आपने ExpandableListView
विशेषता बदलने की कोशिश की है android:groupIndicator="@null"
?
बस, आप छिपे हुए समूह हेडर के लिए ऊंचाई = 0 के साथ एक नया xml लेआउट बनाते हैं। उदाहरण के लिए, यह 'group_list_item_empty.xml' है
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp">
</RelativeLayout>
फिर आपका सामान्य समूह हेडर लेआउट 'your_group_list_item_file.xml' है
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal">
...your xml layout define...
</LinearLayout>
अंत में, आप अपने एडॉप्टर क्लास में सिर्फ गेटग्रुप व्यू पद्धति को अपडेट करें:
public class MyExpandableListAdapter extends BaseExpandableListAdapter{
//Your code here ...
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup viewGroup) {
if (Your condition to hide the group header){
if (convertView == null || convertView instanceof LinearLayout) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.group_list_item_empty, null);
}
return convertView;
}else{
if (convertView == null || convertView instanceof RelativeLayout) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.your_group_list_item_file, null);
}
//Your code here ...
return convertView;
}
}
}
महत्वपूर्ण : लेआउट फ़ाइलों (छिपा हुआ और सामान्य) का रूट टैग अलग होना चाहिए (उदाहरण के लिए, LinearLayout और RelativeLayout के रूप में)
ConvertView.setVisibility (View.GONE) को ट्रिक करनी चाहिए।
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
DistanceHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.list_search_distance_header, parent, false);
if (getChildrenCount(groupPosition)==0) {
convertView.setVisibility(View.GONE);
}