我在同一活動中有兩個自定義listview。然後,第二個listview可以獲得從第一個listview中選擇的itemValue和itemID。那麼現在,我該如何檢查itemID是否已經存在於第二個listview中?提前致謝。檢查自定義listview中的值是否已經存在
這是我第二次列表視圖
private void listOrder(String itemValue, String itemID)
{
HashMap<String, String> map = new HashMap<String, String>();
String quantity = "1";
map.put(FOODID3, itemID);
map.put(FOODNAME3, itemValue);
map.put(FOODQUANTITY3, quantity);
LIST3.add(map);
LISTORDER = (ListView) findViewById(R.id.listOrder);
List3Adapter adapter = new List3Adapter(MainActivity.this, LIST3);
LISTORDER.setAdapter(adapter);
adapter.notifyDataSetChanged();
LISTORDER.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
}
});
}
這是班上的ListView
public class List3Adapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public List3Adapter(Activity a, ArrayList<HashMap<String, String>> d)
{
activity = a;
data = d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View vi = convertView;
if (convertView == null)
{
vi = inflater.inflate(R.layout.row, null);
}
TextView foodID3 = (TextView)vi.findViewById(R.id.foodID3);
TextView foodname3 = (TextView)vi.findViewById(R.id.foodName3);
TextView foodquantity3 = (TextView)vi.findViewById(R.id.foodQuantity3);
HashMap<String,String> food = new HashMap<String, String>();
food = data.get(position);
foodID3.setText(food.get(MainActivity.FOODID3));
foodname3.setText(food.get(MainActivity.FOODNAME3));
foodquantity3.setText(food.get(MainActivity.FOODQUANTITY3));
return vi;
}
}
你在哪裏調用listOrder方法? –
@Tamanna onItemClick – user3040029
第一個listview然後你會得到什麼?你可以檢查哈希映射中的鍵來檢查f條目ID是否已經存在 –