1> 빈을 작성하여 nameOfThePerson 및 frnds에 대한 속성을 갖는 PersonDetails를 말할 수 있습니다.
public class PersonDetails {
private String nameOfThePerson;
private String[] frnds;
public String nameOfThePerson() {
return nameOfThePerson;
}
public void setName(String nameOfThePerson) {
this.nameOfThePerson= nameOfThePerson;
}
public String[] getFrnds() {
return frnds;
}
public void setFrnds(String[] frnds) {
this.frnds= frnds;
}
}
2> sqlite 쿼리를 사용하여 db에서 세부 정보를 가져 와서이 bean을 arraylist에 저장하십시오.
public ArrayList<PersonDetails> getPersonDetails(Context context) {
ArrayList<PersonDetails> lPersonDetailList = new ArrayList<PersonDetails>();
PersonDetails lPersonDetails;
try {
dbName = context.openOrCreateDatabase(Constant.databaseName, Context.MODE_WORLD_WRITEABLE, null);
String query = "SELECT * FROM "NAME OF UR TABLE";
Cursor cursor = dbName.rawQuery(query, null);
cursor.moveToFirst();
if (cursor != null) {
if (cursor.isFirst()) {
do {
lPersonDetails= new PersonDetails();
/*use gettersetters to feed in details to the lPersonDetails object.*/
lPersonDetailList .add(lPersonDetails);
} while (cursor.moveToNext());
}
}
cursor.close();
dbName.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return lPersonDetailList ;
}
3> 확장형 목록보기에 추가하십시오.
public class ExpandableListAdapter extends BaseExpandableListAdapter {
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// get the name of the person from the lPersonDetails object in arraylist position wise
}
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// get the name of the frnds from the lPersonDetails object in arraylist position wise from the string array
}