我正在设计我正在存储消息的自定义INBOX。要获取列表视图,我在我的类中使用以下代码,这将使列表视图膨胀,
public class BinderData1 extends BaseAdapter {
// XML node keys
static final String KEY_SMS = "SMS";
static final String KEY_SMS1 = "SMS1";
static final String KEY_SMS2 = "SMS2";
LayoutInflater inflater;
List<HashMap<String,String>> smsList;
ViewHolder holder;
public BinderData1(Activity act, List<HashMap<String,String>> smsList) {
this.smsList = smsList;
inflater = (LayoutInflater) act
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
// TODO Auto-generated method stub
// return idlist.size();
return smsList.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public void clear()
{
smsList.clear();
notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null){
vi = inflater.inflate(R.layout.sms_list, null);
holder = new ViewHolder();
holder.KEY_SMS= (TextView)vi.findViewById(R.id.KEY_SMS);
holder.KEY_SMS1= (TextView)vi.findViewById(R.id.KEY_SMS1);
holder.KEY_SMS2= (TextView)vi.findViewById(R.id.KEY_SMS2);
vi.setTag(holder);
}
else{
holder = (ViewHolder)vi.getTag();
}
// Setting all values in listview
holder.KEY_SMS.setText(smsList.get(position).get(KEY_SMS));
holder.KEY_SMS1.setText(smsList.get(position).get(KEY_SMS1));
holder.KEY_SMS2.setText(smsList.get(position).get(KEY_SMS2));
/* holder.tvWeather.setText(settingsList.get(position).get(KEY_EXTRAALLOWEDNUMBER));
holder.tvTemperature.setText(settingsList.get(position).get(KEY_FEATURESMODE));*/
// holder.text1=(TextView) vi.findViewById(R.id.KEY_MODE);
return vi;
}
/*
*
* */
static class ViewHolder{
TextView KEY_SMS ;
TextView KEY_SMS1 ;
TextView KEY_SMS2 ;
}
我在这段代码的帮助下显示了ListView,
bindingData1 = new BinderData1(this,smsList);
list1 = (ListView) findViewById( R.id.SMSList );
list1.setAdapter(bindingData1);
list1.setOnItemClickListener(this);
现在假设我正在观看我的消息同时如果出现新消息,列表应该自动更新但是它没有发生。 我存储这些消息的数据库正在服务中。 那么如何对这个列表进行动态处理,就像原来的机器人INBOX一样。