0
我有一个listview
,它显示很好,但是当我点击我的“编辑”操作按钮时,我想listview
使用不同的布局资源,以便按钮显示在每个项目旁边在列表中。更改arrayadapter布局资源,当点击按钮
layout before: listitem_routine
layout I want after "edit" action button clicked: listitem_routine_edit
继承人我的代码工作:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_routines);
datasource = new RoutinesDataSource(this);
datasource.open();
List<Routine> values = datasource.getAllRoutines();
ArrayAdapter<Routine> adapter = new ArrayAdapter<Routine>(this,
R.layout.listitem_routine, R.id.listitem_routine_name, values);
setListAdapter(adapter);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
ArrayAdapter<Routine> adapter = (ArrayAdapter<Routine>) getListAdapter();
// Handle item selection
switch (item.getItemId()) {
case R.id.button_routines_edit:
// change the list view adapter resource layout to *_edit
// hide this button and show the "done editing (checkmark)" button
return true;
default:
return super.onOptionsItemSelected(item);
}
}
我知道,R.id.button_routines_edit
作品的情况下,因为我做了烤面包被点击时。这很美味。我自从删除该代码...
但任何方式,当点击R.id.button_routines_edit
时,如何改变布局资源?所有的代码在那里,我只是不知道如何去改变布局资源,然后明显更新listview
以显示新的行布局...
是的,我理解了它,我也不得不通过'列表重新抓住这个函数内的列表中的值值= datasource.getAllRoutines();' –
scarhand