Nach dem Lesen von Daten aus einer CSV-Datei, ich habe es in der Liste gespeichert.Fügen Sie Daten von Liste <String[]> zu Liste <String> und Karte <Striing, Striing>
List <String>listDataHeader = new ArrayList<String>();
Map<String,String>listDataChild = new HashMap<String, String>();
List<String[]> termDefinition = csv.read();
Dann Iirate über die Liste und möchte die Daten speichern. Wie es jetzt geschrieben ist, nehme ich die richtigen Tasten, aber nicht die Werte:
Kannst du mir helfen? Vielen Dank!
EDIT: Ich muss Daten in ExpandavbleListVew füllen. Der listdataHeader ist das Hauptthema, das listdataChild ist der Unterpunkt. In der CSV gibt es nur zwei Spalten im Format Termdefinition. Momentan werden Hauptthemen (vom listDataheader) korrekt gespeichert. Nach dem Korrigieren der Schleife (siehe oben) habe ich für jedes Hauptelement die Definition so oft wie die Größe der Schleife (10 in dem Fall). Hier
ist die expandableListView Klasse:
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;
}
}
Zwei nur. Vielen Dank! – VyaraG
Können Sie mehr Details darüber mitteilen? Zum Beispiel: Beispiel Eingabedaten, erwartete Ausgabedaten und Ihre aktuelle Ausgabe. – Minh
Schauen Sie oben, danke! – VyaraG