Quelqu'un peut-il m'aider s'il vous plaît comment développer automatiquement le groupe dans ma liste extensible, j'ai seulement un groupe. avec 5 articles. Je veux l'agrandir automatiquement, donc je n'ai pas besoin de cliquer dessus. Je groupExpand (0), mais ca marche pas :(.Voici mon code completExpandableListview Comment Auto groupExpand - Android
public class ExpandActivity extends ExpandableListActivity {
//String[] actions = new String[] {
// "",
// "Settings",
// "About",
//};
ListView listView ;
TextView txtView;
@SuppressLint("SimpleDateFormat")
@SuppressWarnings({ "unchecked", "deprecation" })
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.expand);
((ExpandableListView) listView).expandGroup(0);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item.
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView.
createChildList(), // childData describes second-level entries.
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item"}, // Keys in childData maps to display.
new int[] { R.id.grp_child} // Data under the keys above go into these TextViews.
);
setListAdapter(expListAdapter); // setting the adapter in the list.
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
for(int i = 0 ; i < 1 ; ++i) { // 15 groups........
HashMap m = new HashMap();
m.put("Group Item","Updates"); // the key and it's value.
result.add(m);
((ExpandableListView) listView).expandGroup(0);
}
return (List)result;
}
/* creatin the HashMap for the children */
@SuppressWarnings("unchecked")
private List createChildList() {
ArrayList result = new ArrayList();
for(int i = 0 ; i < 1 ; ++i) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for(int n = 0 ; n < 1 ; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "DILC");
secList.add(child);
}
result.add(secList);
ArrayList secList2 = new ArrayList();
for(int n = 0 ; n < 1 ; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "OVRCD");
secList.add(child);
}
result.add(secList2);
ArrayList secList3 = new ArrayList();
for(int n = 0 ; n < 1 ; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "UPD Information");
secList.add(child);
}
result.add(secList3);
ArrayList secList4 = new ArrayList();
for(int n = 0 ; n < 1 ; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "UP System");
secList.add(child);
}
result.add(secList4);
ArrayList secList5 = new ArrayList();
for(int n = 0 ; n < 1 ; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "All Updates");
secList.add(child);
}
result.add(secList5);
}
return result;
}
public void onContentChanged () {
System.out.println("onContentChanged");
super.onContentChanged();
}
/* This function is called on each child click */
@SuppressLint("NewApi")
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
ExpandableListAdapter adap = parent.getExpandableListAdapter();
int gp = (int) adap.getGroupId(groupPosition);
int cp = (int) adap.getChildId(groupPosition, childPosition);
if (gp == 0) {
switch (cp) {
case 0:
Intent intent = new Intent(getApplicationContext(),
RssTabsActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 1:
Intent intent1 = new Intent(getApplicationContext(),
OVRCD.class);
startActivity(intent1);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 2:
Intent intent2 = new Intent(getApplicationContext(),
UPDInfo.class);
startActivity(intent2);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 3:
Intent intent3 = new Intent(getApplicationContext(),
UPSystem.class);
startActivity(intent3);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 4:
Intent intent4 = new Intent(getApplicationContext(),
ALLUPD.class);
startActivity(intent4);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
}
} else if (gp == 1) {
switch (cp) {
case 0:
Intent intent = new Intent(getApplicationContext(),
RssTabsActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 1:
Intent intent1 = new Intent(getApplicationContext(),
RssTabsActivity.class);
startActivity(intent1);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 2:
Intent intent2 = new Intent(getApplicationContext(),
RssTabsActivity.class);
startActivity(intent2);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 3:
Intent intent3 = new Intent(getApplicationContext(),
RssTabsActivity.class);
startActivity(intent3);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
case 4:
Intent intent4 = new Intent(getApplicationContext(),
RssTabsActivity.class);
startActivity(intent4);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_in);
break;
}
}
return true;
};
@SuppressWarnings("null")
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent){
ExpandableListView expView = getExpandableListView();
ContextThemeWrapper context = null;
expView.setChildIndicator(context.getResources().getDrawable(
R.drawable.arrow_right));
expView.setChildDivider(getResources().getDrawable(R.color.grey));
expView.setDividerHeight(2);
return parent;
}
/* This function is called on expansion of the group */
public void onGroupExpand (int groupPosition) {
try{
System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
}catch(Exception e){
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}
'for (int i = 1; i <= countChildren; i ++) listView.expa ndGroup (i - 1); ' – g00dy
où devrais-je mettre cela dans le code? – jajaja
Placez-le lorsque vous souhaitez étendre ExpandListView. – g00dy