开发者

Android. update ExpandableListView

I have the following problem:

I would like to change value of ExpandableListView's cell on click. How should I do that?

Here is what I'm using:

    public class TemplateActivity extends ExpandableListActivity {

     private SimpleExpandableListAdapter expListAdapter = null;

     protected void onCreate(Bundle savedInstanceState) {
  setContentView(R.layout.template_create);
     expListAdapter = new SimpleExpandableListAdapter(
    this, createGroupList(), 
    R.layout.template_create_group_row, 
    new String[] { KEY_GROUP }, 
    new int[] { R.id.create_template_groupname }, 
    createChildList(), 
    R.layout.flower_template_create_child_row, 
    new String[] { KEY_ATTRIBUTE_VALUE }, 
    new int[] { R.id.flowerx_text_attr }
  );

  setListAdapter(expListAdapter);

     }

 private List<HashMap<String, String>> createGroupList() {
  ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();

  for (String entryKey: <ArrayOfGroupTitles>) {
   HashMap<String, String> m = new HashMap<String, String>();
   m.put(KEY_GROUP, entryKey);
   result.add(m);
  }

  return result;
 }

 private List<ArrayList<HashMap<String, Object>>> createChildList() {
  ArrayList<ArrayList<HashMap<String, Object>>> result = new ArrayList<ArrayList<HashMap<String, Object>>>();
  for (String entryKey: fieldsInList.keySet()) {
   ArrayList<HashMap<String, Object>> secList = new ArrayList<HashMap<String, Object>>();

   HashMap<String, Object> att开发者_JS百科rVal = new HashMap<String, Object>();
   attrVal.put(KEY_ATTRIBUTE_VALUE, String.valueOf(fieldsInList.get(entryKey).getFieldValue()));
   secList.add(attrVal);
   result.add(secList);
  }

  return result;
 }

Application is in progress stage, so attrVal will contain several attributes ( which can be put or not depend on some logic), so I'm using this type of adapter and this way of filling cells' data.

fieldsInList - external variable of LinkedHashMap type.

I have a function which can change one of the member's of fieldsInList variable. How should I notify my expListAdapter or ExpanableListView to be refreshed?


expListAdapter.notifyDataSetChanged(); - to notify adapter that data has changed :

For onclick :

OnChildClickListener myOnChildClick = new OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, int arg3,
                long arg4) {
            // TODO Auto-generated method stub
            return false;
        }

    };

and setOnChildClickListener(myOnChildClick); in onCreate


To update cells for expanableListView you should use List<ArrayList<HashMap<Object, Object>>> variable during creating adapter. It doesn't work for me first time, because I use internal method, which created new list. Maybe this fact is the cause of problem. As Alex said, you need call adapter.notifyDataSetChanged() to make the changes applied to the ExpandableList. Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜