Ce fut une expérience d'apprentissage géniale, mais j'ai finalement presque terminé avec mon adaptateur expandablelistview. Il a des cases à cocher sur les groupes et les enfants, donc intuitivement, vous pouvez désactiver/activer toutes les vérifications sur les enfants par checkbox. tout ce qui reste maintenant est de faire cocher la vue de groupe correspondant aux vues des enfants. quand j'essaye de le faire s'écraser.cablage case à cocher expandablelistview case à cocher
for(int i = 0; i < check_states.get(groupPosition).size(); i++) {
if (check_states.get(groupPosition).get(i) == false) {
Log.d ("Meat", "Child checkboxes are not all checked!!!");
}
}
Je suis très sûr maintenant que c'est parce que j'appelle ces commandes avant la arraylist est terminée peuplant -> « check_states » est un arraylist de ArrayLists que j'utiliser pour garder les checkstates des cases à cocher.
Donc, ma question est très simple: comment attendre que l'arrayliste ait fini de remplir avant d'appeler mes commandes? J'ai examiné ce que je peux, mais ils semblent un peu plus impliqués que ce que cela vaut. Je préfèrerais mettre en place un menu long-click plutôt que de mettre en place un fil séparé ou d'épargner 10 lignes de code pour quelque chose d'aussi maigre que ça.
EDIT: mis à jour avec logcat
10-06 19:18:08.204: W/dalvikvm(540): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-06 19:18:08.224: E/AndroidRuntime(540): FATAL EXCEPTION: main
10-06 19:18:08.224: E/AndroidRuntime(540): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
10-06 19:18:08.224: E/AndroidRuntime(540): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
10-06 19:18:08.224: E/AndroidRuntime(540): at java.util.ArrayList.get(ArrayList.java:311)
10-06 19:18:08.224: E/AndroidRuntime(540): at com.mangodeveloper.mcathomie.McatTopicsExpandableListAdapter.getGroupView(McatTopicsExpandableListAdapter.java:166)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:445)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.ListView.makeAndAddView(ListView.java:1745)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.ListView.fillDown(ListView.java:670)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.ListView.fillFromTop(ListView.java:727)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.ListView.layoutChildren(ListView.java:1598)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.View.layout(View.java:7175)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.View.layout(View.java:7175)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.View.layout(View.java:7175)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.View.layout(View.java:7175)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.View.layout(View.java:7175)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.View.layout(View.java:7175)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.os.Looper.loop(Looper.java:123)
10-06 19:18:08.224: E/AndroidRuntime(540): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-06 19:18:08.224: E/AndroidRuntime(540): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 19:18:08.224: E/AndroidRuntime(540): at java.lang.reflect.Method.invoke(Method.java:507)
10-06 19:18:08.224: E/AndroidRuntime(540): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-06 19:18:08.224: E/AndroidRuntime(540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-06 19:18:08.224: E/AndroidRuntime(540): at dalvik.system.NativeStart.main(Native Method)
Modifier à nouveau: Voici à peu près les parties pertinentes de l'adaptateur extensible
public class McatTopicsExpandableListAdapter extends BaseExpandableListAdapter {
...
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
LayoutInflater viewInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = viewInflater.inflate(R.layout.mtopics_childview, parent, false);
holder = new ViewHolder();
holder.text = (TextView)convertView.findViewById(R.id.mtopicschildtv);
holder.checkbox = (CheckBox)convertView.findViewById(R.id.mtopicchildchkbox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getChild(groupPosition, childPosition).toString());
for(int i = 0; i < children.length; i++) {
ArrayList<Boolean> tmp = new ArrayList<Boolean>(children[i].length);
for(int j = 0; j < children[i].length; j++) {
tmp.add(true);
}
check_states.add(tmp);
}
if (check_states.get(groupPosition).get(childPosition) == true) {
holder.checkbox.setChecked(true);
}else{ holder.checkbox.setChecked(false);
}
holder.checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (holder.checkbox.isChecked()) {
check_states.get(groupPosition).set(childPosition, true);
}else{ check_states.get(groupPosition).set(childPosition, false);
}
}
});
return convertView;
}
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater viewInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = viewInflater.inflate(R.layout.mtopics_groupview, parent, false);
holder = new ViewHolder();
holder.text = (TextView)convertView.findViewById(R.id.mtopicsgrouptv);
holder.checkbox = (CheckBox)convertView.findViewById(R.id.cb_group);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(getGroup(groupPosition).toString());
for(int i = 0; i < check_states.get(groupPosition).size(); i++) {
if (check_states.get(groupPosition).get(i) == false) {
Log.d ("Meat", "Child checkboxes are not all checked!!!");
}
}
holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
for(int i = 0; i < check_states.get(groupPosition).size(); i++) {
check_states.get(groupPosition).set(i, true);
}
} else if (!isChecked)
for(int i = 0; i < check_states.get(groupPosition).size(); i++) {
check_states.get(groupPosition).set(i, false);
}
notifyDataSetChanged();
}
});
return convertView;
}
// additional components
ArrayList<ArrayList<Boolean>> check_states = new ArrayList<ArrayList<Boolean>>(children.length);
static class ViewHolder {
TextView text;
CheckBox checkbox;
}
}
Vous devez ajouter la pile à l'exception de 'logcat'. Qu'est-ce qui rend le remplissage d'une liste de liste avec des valeurs 'boolean' si long? – Luksprog
et que diriez-vous, boolean allChildBoxesChecked =! Check_states.get (groupPosition) .contains (false); Cela ne résoudra pas votre problème, cependant. s'il vous plaît signaler logcat et le code –
là. Je l'ai mis à jour avec logcat. J'ai des raisons de croire qu'il doit y avoir une différence de temps de quelques millisecondes parce que si je place le code juste après la méthode de population arraylist, cela fonctionne sans accroc. merci pour cette friandise élégante, cependant, Tamir. – mango