何時間もの間、Expandablelistview の子に値を代入しようとしていますが、結果は同じです。
SQLite データベースから値を取得しています。そして、それらを配列文字列に変換します。
そして、展開可能なリストビューの子に値を入れています。この上:
respuestas = new String[charSequenceItems.length][1];
for (int i = 0; i < charSequenceItems.length; i++) {
//The group is 0 and childs are many as charSequenceItems length
respuestas[0][i] = charSequenceItems[i];
}
そして、私はこのエラーを受け取ります:
java.lang.ArrayIndexOutOfBoundsException
しかし、私がこの方法でそれをやっているとき (私は charSequenceItems の値を子ではなく展開可能なリストのグループに入れています):
respuestas = new String[charSequenceItems.length][1];
for (int i = 0; i < charSequenceItems.length; i++) {
//The values of charSequenceItems are assigned to groups and not childs.
respuestas[i][0] = charSequenceItems[i];
}
問題なく動作します。
チャイルドに値を入れる組み合わせをたくさん試しましたが、誰もうまくいきませんでした。
私は何を間違っていますか?
前もって感謝します。
それは私のコード全体です:
public class Resumen extends ExpandableListActivity {
String[] charSequenceItems;
private MyExpandableListAdapter mAdapter;
private String[] preguntas = { "Preguntas contrato", "Especies detectadas",
"Medidas estructurales", "Medidas higiénico sanitarias",
"Medidas sobre hábitos", "Medidas de control directo", "Productos" };
private String productos[];
private String[][] respuestas;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resumenlista);
List<String> uGraduateNamesList = new ArrayList<String>();
AndroidOpenDbHelper openHelperClass = new AndroidOpenDbHelper(this);
SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();
Cursor cursor = sqliteDatabase.query("ProductosTemporal", null, null,
null, null, null, null);
startManagingCursor(cursor);
while (cursor.moveToNext()) {
String descripcionproducto = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.descripcionproducto));
uGraduateNamesList.add(descripcionproducto);
charSequenceItems = uGraduateNamesList
.toArray(new String[uGraduateNamesList.size()]);
}
cursor.close();
sqliteDatabase.close();
respuestas = new String[charSequenceItems.length][1];
for (int i = 0; i < charSequenceItems.length; i++) {
respuestas[3][0] = charSequenceItems[1];
}
// Set up our adapter
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
}
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
public Object getChild(int groupPosition, int childPosition) {
return respuestas[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return respuestas[groupPosition].length;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
TextView textView = new TextView(Resumen.this);
textView.setLayoutParams(lp);
textView.setPadding(60, 5, 0, 5);
textView.setTextAppearance(getBaseContext(), R.style.TitleText);
return textView;
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// Including a custom view for the child image and text
View inflatedView = View.inflate(getApplicationContext(),
R.layout.nombrefilaresumen, null);
inflatedView.setPadding(50, 0, 0, 0);
TextView textView = (TextView) inflatedView
.findViewById(R.id.textView1);
// lets set up a custom font
textView.setTextSize(17);
textView.setText(getChild(groupPosition, childPosition).toString());
return inflatedView;
}
public Object getGroup(int groupPosition) {
return preguntas[groupPosition];
}
public int getGroupCount() {
return preguntas.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
}