我有一个ListView,它显示了一个对象列表,例如CustomObject。
列表视图显示正常。
我在每个自定义对象中都有一个Callback侦听器,用于更新CustomOject中的布尔成员。
public class ListCustomObject extends Activity {
private CustomListAdapter adapter;
private ListView customList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new CustomListAdapter (this);
customList= (ListView) findViewById(R.id.custom_list);
List<CustomObject> customObjectList= getCustomObjects();
adapter.addObjects(customObjectList);
customList.setAdapter(adapter);
}
class CustomObject implements MonitoringListner{
String name;
boolean entered;
@Override
public void onEnteredRegion() {
entered=true;
}
@Override
public void onExitedRegion() {
entered=false;
}
}
我正在显示&#39;姓名&#39;并且&#39;进入&#39;在listItem。
问题是,当回调到来并将布尔值更改为true时。它没有反映在列表视图中。
如何在回调事件到达相应对象时更新相应的列表项?
请帮忙。
等待一些答案。
答案 0 :(得分:1)
使用此代码通知listview
public class ListCustomObject extends Activity {
private CustomListAdapter adapter;
private ListView customList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adapter = new CustomListAdapter (this);
customList= (ListView) findViewById(R.id.custom_list);
List<CustomObject> customObjectList= getCustomObjects();
adapter.addObjects(customBeaconList);
customList.setAdapter(adapter);
}
class CustomObject implements MonitoringListner{
private CustomListAdapter adapter;
public CustomObject(CustomListAdapter adapter) {
this.adapter = adapter;
}
String name;
boolean entered;
@Override
public void onEnteredRegion() {
entered=true;
adapter.notifyDataSetChanged();
}
@Override
public void onExitedRegion() {
entered=false;
adapter.notifyDataSetChanged();
}
}
当你想创建CustomObject传递适配器到构造函数。