在我的 android 应用程序中,我使用自定义列表来显示一个日志,其中包含电话号码并将状态作为项目发送。当我向电话号码发送短信时,我将电话和状态更新为待处理。当短信送达时,我想更新为特定客户送达的状态。这个怎么做。请找到我用于我的应用程序的代码
谢谢你
我的活动
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();
}
}
数据适配器类
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;
}
}