我在屏幕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 itemDetailsrrayList;
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;
}
答案 0 :(得分:0)
在启动“详细信息”活动时,您需要使用startActivityForResult()。
请查看此处的答案,其中详细解释了How to manage `startActivityForResult` on Android?
答案 1 :(得分:0)