listview SimpleAdapter 刷新问题
public class NasActivity extends Activity {
public static final String TAG = "nasActivity";
private Context mContext;
ListView list;
SimpleAdapter adapter;
private int Pre_Num = 0;
private String[] info;
private String pre_name="~$";
private String[] name={""};
public BroadcastReceiver XXXX = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
....
updateview();
}
};
private void updateview() {
getInfo();
adapter =new SimpleAdapter(this, getData(), R.layout.listitems,
new String[] {"name","info"},
new int[] {R.id.name,R.id.info});
list.setAdapter(adapter);
}
private void getInfo()
{ ......
change the info[];
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.nasview);
list = (ListView) findViewById(R.id.ListView01);
Pre_Num=name.length;
info =new String[Pre_Num];
this.registerReceiver(XXXX, new IntentFilter(
"intent.action.XXXX"));
getInfo();
adapter =new SimpleAdapter(this, getData(), R.layout.listitems,
new String[] {"name","info"},
new int[] {R.id.name,R.id.info});
list.setAdapter(adapter);
}
private List<Map<String,Object>> getData(){
List<Map<String, Object>> list =new ArrayList<Map<String,Object>>();
Map<String, Object> map =new HashMap<String, Object>();
for(int i=0;i<Pre_Num;i++)
{
map =new HashMap<String, Object>();
map.put("name", name[i]+pre_name);
map.put("info", info[i]);
list.add(map);
}
return list;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
this.unregisterReceiver(XXXX);
super.onDestroy();
}
}
[解决办法]
你想问什么,还是科普篇?
[解决办法]