CSVファイルからデータを読み込んだ後、リストに保存しています。データをリストに挿入<String[]>をリスト<String>にマップしてください。<ストライピング、ストライピング>
List <String>listDataHeader = new ArrayList<String>();
Map<String,String>listDataChild = new HashMap<String, String>();
List<String[]> termDefinition = csv.read();
次に、リストを繰り返し、データを保存します。今書いているとおり、私は正しいキーをとっていますが、値はありません:
for (String[] term : termDefinition) {
listDataHeader.add(term[0]);
listDataChild.put(term[0], term[1]);
}
私を助けてもらえますか?ありがとう!
EDIT: ExpandavbleListVewにデータを入力する必要があります。 listdataHeaderはメイントピックで、listdataChildはサブ項目です。 CSVにはterm定義の形式で2つの列しかありません。現時点では、(listDataheaderの)主要トピックが正しく格納されています。ループを修正した後(上記を参照)、ループのサイズ(ケースの10)の何倍も表示される定義を、各メインアイテムに対して持っています。ここで
がexpandableListViewクラスです:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listDataHeader; // header titles
// child data in format of header title, child title
private Map<String, String> listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
Map<String, String> listChildData) {
this.context = context;
this.listDataHeader = listDataHeader;
this.listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this.listDataChild.get(this.listDataHeader.get(groupPosition));
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.itemList);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this.listDataChild.size();
}
@Override
public Object getGroup(int groupPosition) {
return this.listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this.listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.header, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.headerList);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
つ。ありがとう! – VyaraG
これについて詳しく知りたいですか?例:入力データのサンプル、予想される出力データ、および現在の出力。 – Minh
上記をご覧ください、ありがとう! – VyaraG