2016-05-30 10 views
-1

public class CustomExpandableListAdapter erweitert BaseExpandableListAdapter implementiert ExpandableListAdapter {expandablelistview Kind Ansicht vertikale Linie Anzeige in Android

public Context context; 

private LayoutInflater vi; 
private String[][] data; 
int _objInt; 
public static Boolean checked[] = new Boolean[1]; 


private static final int GROUP_ITEM_RESOURCE = R.layout.list_group; 
private static final int CHILD_ITEM_RESOURCE = R.layout.list_item; 


public CustomExpandableListAdapter(Context context, Activity activity, String[][] data) { 
    this.data = data; 
    this.context = context; 
    vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    _objInt = data.length; 


} 

public String getChild(int groupPosition, int childPosition) { 
    return data[groupPosition][childPosition]; 
} 

public long getChildId(int groupPosition, int childPosition) { 
    return childPosition; 
} 

public int getChildrenCount(int groupPosition) { 
    return data[groupPosition].length; 
} 

@Override 
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    View v = convertView; 
    String child = getChild(groupPosition, childPosition); 
    int id_res = 0; 
    if(groupPosition == 0){ 
     if(childPosition == 0) id_res = R.mipmap.div2; 
     if(childPosition == 1) id_res = R.mipmap.div1; 

    } 
    else if(groupPosition == 1){ 
     if(childPosition == 0) id_res = R.mipmap.div2; 
     if(childPosition == 1) id_res = R.mipmap.div1; 
    } 
    else if(groupPosition == 2){ 
     if(childPosition == 0) id_res = R.mipmap.div2; 
     if(childPosition == 1) id_res = R.mipmap.div1; 
    } 
    else if(groupPosition == 3){ 
     if(childPosition == 0) id_res = R.mipmap.div2; 
     if(childPosition == 1) id_res = R.mipmap.div3; 
     if(childPosition == 2) id_res = R.mipmap.div1; 
    } 

    if (child != null) { 
     v = vi.inflate(CHILD_ITEM_RESOURCE, null); 
     TextView text = (TextView)v.findViewById(R.id.text1); 
     ImageView imageview = (ImageView)v.findViewById(R.id.image1) ; 
     text.setText(Html.fromHtml(child)); 

     imageview.setImageResource(id_res); 
    } 
    return v; 
} 

public String getGroup(int groupPosition) { 
    return "group-" + groupPosition; 
} 
public int getGroupCount() { 
    return data.length; 
} 
public long getGroupId(int groupPosition) { 
    return groupPosition; 
} 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    View v = convertView; 
    String group = null; 
    int id_res = 0; 
    long group_id = getGroupId(groupPosition); 
    if(group_id == 0){ 
     group = "Gate Pass"; 
     id_res = R.mipmap.getpass; 
    } 
    else if(group_id == 1){ 
     group = "Vessel/Rake"; 
     id_res = R.mipmap.vessel; 
    } 
    else if(group_id == 2){ 
     group = "Last leg"; 
     id_res = R.mipmap.lastleg; 
    } 
    else if(group_id == 3){ 
     group = "Other"; 
     id_res = R.mipmap.other; 
    } 

    if (group != null) { 
     v = vi.inflate(GROUP_ITEM_RESOURCE, null); 

     TextView text = (TextView)v.findViewById(R.id.text1); 
     ImageView imageview = (ImageView)v.findViewById(R.id.image1) ; 
     ImageView img = (ImageView)v.findViewById(R.id.indicatior); 
     text.setText(Html.fromHtml(group)); 
     imageview.setImageResource(id_res); 
     if (isExpanded) { 

      img.setImageResource(R.drawable.up_arrow); 
     } else { 
      img.setImageResource(R.drawable.down_arrow); 
     } 

    } 

    return v; 
} 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    return true; 
} 
public boolean hasStableIds() { 
    return true; 
} 

} `Ich will eine vertikale Linie für alle untergeordneten Elemente in einer Gruppe eines ExpandableListView ziehen. Mein Kind Artikel ist ein Textview, also versuchte ich eine vertikale Linie in jedem Kind Textview, so zu zeichnen:

+0

@Praful Patel bitte posten Sie Ihren Code – Nisarg

+0

Können Sie ein Beispiel geben? – Masum

+0

mein Code ist über @Nisarg –

Antwort

0

Für vertikale Linie hinzufügen view in xml Datei

<View 
    android:layout_width="1dp" 
    android:layout_height="fill_parent" 
    android:background="#FF0000FF" /> 

Höhe einstellt nach Ihren Bedürfnissen.