一旦用户单击列表中的一个项目,我在屏幕 A 中有列表视图,它导航到下一个屏幕,他可以在其中查看所选项目的更多详细信息。
用户可以在屏幕 B 中修改该项目。一旦用户返回屏幕 A,更改就完成了,该列表必须更新如何操作。
我使用的列表是静态的。
我使用的代码是:
ArrayList<ItemDetails> image_details = GetSearchResults();
final ListView lv1 = (ListView) findViewById(R.id.listV_main);
lv1.setAdapter(new ItemListBaseAdapter(this, image_details));
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
ItemDetails obj_itemDetails = (ItemDetails)o;
Intent i = new Intent(DemoPastSubstitutions.this,DemoPastSubstitutionsDetail.class);
i.putExtra("substitutesName", obj_itemDetails.getName());
i.putExtra("positionCompany", obj_itemDetails.getDesignation());
i.putExtra("phone", obj_itemDetails.getphone());
i.putExtra("email", obj_itemDetails.getEmail());
i.putExtra("Date", obj_itemDetails.getDates());
i.putExtra("imageNo", obj_itemDetails.getImageNumber());
startActivity(i);
}
});
}
private ArrayList<ItemDetails> GetSearchResults(){
ArrayList<ItemDetails> results = new ArrayList<ItemDetails>();
ItemDetails item_details = new ItemDetails();
item_details.setName("Diesel Dean");
item_details.setDates("From 02/19/2013 - 04/03/2013");
item_details.setDesignation("Manager");
item_details.setphone("+9164589022");
item_details.setEmail("diesel.dean@sap.com");
item_details.setImageNumber(1);
item_details = new ItemDetails();
item_details.setName("Kate Hudson");
item_details.setDates("From 01/23/2013 - 02/15/2013");
item_details.setDesignation("Manager");
item_details.setphone("+916458902");
item_details.setEmail("kate.hudson@sap.com");
item_details.setImageNumber(2);
results.add(item_details);
item_details = new ItemDetails();
item_details.setName("Kevin James");
item_details.setDates("From 01/01/2013 - 01/02/2013");
item_details.setDesignation("Manager");
item_details.setphone("+9164589023");
item_details.setEmail("kevin.james@sap.com");
item_details.setImageNumber(3);
results.add(item_details);
item_details = new ItemDetails();
item_details.setName("Gray Cruz");
item_details.setDates("From 01/10/2013 - 01/20/2013");
item_details.setDesignation("Manager");
item_details.setphone("+9164589025");
item_details.setEmail("gray.cruz@sap.com");
item_details.setImageNumber(4);
results.add(item_details);
return results;
}
基础适配器代码:private static ArrayList itemDetailsarrayList;
private Integer[] imgid = {
R.drawable.p1,
R.drawable.bb2,
R.drawable.p2,
R.drawable.bb5,
R.drawable.bb6,
R.drawable.d1
};
private LayoutInflater l_Inflater;
public ItemListBaseAdapter(Context context, ArrayList<ItemDetails> results) {
itemDetailsrrayList = results;
l_Inflater = LayoutInflater.from(context);
}
public int getCount() {
return itemDetailsrrayList.size();
}
public Object getItem(int position) {
return itemDetailsrrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.item_details_view, null);
holder = new ViewHolder();
holder.txt_itemName = (TextView) convertView.findViewById(R.id.name);
holder.txt_itemDescription = (TextView) convertView.findViewById(R.id.itemDescription);
//holder.txt_itemPrice = (TextView) convertView.findViewById(R.id.price);
holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txt_itemName.setText(itemDetailsrrayList.get(position).getName());
holder.txt_itemDescription.setText(itemDetailsrrayList.get(position).getDates());
holder.itemImage.setImageResource(imgid[itemDetailsrrayList.get(position).getImageNumber() - 1]);
return convertView;
}
static class ViewHolder {
TextView txt_itemName;
TextView txt_itemDescription;
//TextView txt_itemPrice;
ImageView itemImage;
}