我有一个具有 ExpandableList 的 android 应用程序,getChildView(int,int,boolean,View,ViewGroup)
如果某些条件为真,我想在其适配器中重绘 ExpandableList,我该怎么办?
问问题
54 次
1 回答
0
这是答案,但不建议这样做:
这是您的活动:
public class MyActivity extends Activity implements MyAdapterListener{
private ExpandableListView expandableListView1;
private MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
expandableListView1 = (ExpandableListView) findViewById(R.id.expandableListView1);
adapter = new MyAdapter(this);
expandableListView1.setAdapter(adapter);
}
@Override
public void doRefresh() {
adapter.notifyDataSetChanged();
}
}
这是您的适配器:
public class MyAdapter extends BaseExpandableListAdapter{
public interface MyAdapterListener{
public void doRefresh();
}
private MyAdapterListener listener;
public MyAdapter(MyAdapterListener listener){
this.listener = listener;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if(some condition is true and you want to refresh the list view){
listener.doRefresh();
}
return null;
}
}
希望这可以帮助。
于 2013-08-08T07:44:13.797 回答