using expandable list adapter

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

using expandable list adapter

Postby vinaymundrathi » Mon Nov 16, 2009 12:58 pm

How to handle expanadablelistadapter by using hash map where child list contains entries which are added up on request?please help me ?



protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.diet_diary);
userSelectedList =new HashMap<String,String>();
m_dbHelper = new NutriDbAdapter(this);
m_dbHelper.open();

Cursor c1 = m_dbHelper.getDietDates();


HashMap<String, ArrayList<String>> hashMap = new HashMap<String, ArrayList<String>>();
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();

c1.moveToFirst();
//Map<String, String> hashMap= new HashMap<String, String>();


do {
String key=c1.getString(c1.getColumnIndex(NutriDbAdapter.DD_TIME_STAMP ));
if( hashMap.containsKey(key) ){

String value=c1.getString(c1.getColumnIndex(NutriDbAdapter.KEY_SHRT_DESC ));
// Map<String, String> groupMap = new HashMap<String, String>();
// groupData.add(hashMap );
ArrayList<String> s1=hashMap.get( key);
s1.add(value);
hashMap.put(key, s1);

Log.d("previousdietitem1", s1.get(0));
// groupData.add(hashMap);

}
else{

String value=c1.getString(c1.getColumnIndex(NutriDbAdapter.KEY_SHRT_DESC ));
ArrayList<String> s1 = new ArrayList<String>();
// List<Map<String, String>> s1= new ArrayList<Map<String, String>>();

s1.add( value);
hashMap.put(key, s1);
Log.d("newdietitem2", s1.get(0));

}

}while(c1.moveToNext());
mGroupIdColumnIndex = groupCursor.getColumnIndexOrThrow(NutriDbAdapter.KEY_ID);



String key=NutriDbAdapter.DD_TIME_STAMP;
String s2 = NutriDbAdapter.KEY_SHRT_DESC ;

Collection<ArrayList<String>> c = hashMap.values();

Set<String> s5=hashMap.keySet();
String[] array = (String[])s5.toArray(new String[s5.size()]);


ArrayList s3 = new ArrayList(c);
//String s5 = null;
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
this,
s3,
android.R.layout.simple_expandable_list_item_1,
new String[] {array[]},
new int[] { android.R.id.text1, android.R.id.text2 },
s2,
android.R.layout.simple_expandable_list_item_2,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 }
);

setListAdapter(mAdapter);

m_dbHelper.close();
c1.close();
}
vinaymundrathi
Freshman
Freshman
 
Posts: 5
Joined: Fri Sep 11, 2009 8:44 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests