0

我正在设计我存储消息的自定义收件箱。要获取列表视图,我在我的类中使用以下代码,它将膨胀列表视图,

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);

现在假设我正在观看我的消息,如果有新消息出现,列表应该自动更新但它没有发生。我存储这些消息的数据库位于服务中。那么如何像原始的android收件箱一样动态地处理这个列表。

4

0 回答 0