更新android中自定义列表中的特定项目

时间:2012-12-10 07:35:26

标签: android android-listview

在我的Android应用程序中,我使用自定义列表来显示日志,其中包含电话号码并将状态作为项目发送。当我向短信发送短信时,我将手机和状态更新为待处理。 当短信发送时,我想更新为特定客户提供的状态。这该怎么做。请找到我用于我的应用程序的代码

谢谢

myactivity

public class MainActivity extends Activity {
private ListView listview1;
private Vector<Data> datas = null;
private DataAdapter adapter = null; 
private int clickCounter = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    datas = new Vector<Data>();
    adapter = new DataAdapter(this, R.layout.listview_item_row, datas);
    listview1 = (ListView)findViewById(R.id.listView1);
    View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
    listview1.setAdapter(adapter);
 }

public void sendSMS() {
    Data data1 = new Data(R.drawable.ic_launcher, "987654321", "Pending");
    datas.add(0, data1);
    adapter.notifyDataSetChanged();
}
}

DataAdapter类

public class DataAdapter extends ArrayAdapter<Data>{
Context context;
int layoutResouceId;
Vector<Data> datas = null;

public DataAdapter(Context context, int layoutResourceId, Vector<Data> datas){
    super(context, layoutResourceId, datas);
    this.context = context;
    this.layoutResouceId = layoutResourceId;
    this.datas = datas;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    DataHolder holder = null;

    if( row == null ){
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResouceId, parent, false);

        holder = new DataHolder();
        holder.phoneno = (TextView)row.findViewById(R.id.phoneno);
        holder.status = (TextView)row.findViewById(R.id.status);

        row.setTag(holder);
    }
    else {
        holder = (DataHolder)row.getTag();
    }

    Data data = datas.get(position);
    holder.txtPhoneno.setText(data.title);
    holder.txtStatus.setText(data.desc);        
    return row;
}

static class DataHolder {
    TextView txtPhoneno;
    TextView txtStatus;
}
}

0 个答案:

没有答案