我有Model_BarcodeDetail
類型,當我在EditText上輸入任何條形碼其conatins像barcode, area,location,color
等 屬性的列表,我想找尋條形碼列表(列表可以有類似條形碼具有相似的地區和位置或不同的面積和位置),如果我輸入的條形碼和我列表中的相似條形碼具有相同的面積和位置,則我想doSomething()
其他doSomethingElse()
。如何搜索包含特定動態值的列表
我試過的代碼是:
private List<String> barcodeList = new ArrayList<String>();
barcode = editText_barcode.getText().toString().trim();
if ((scanned_barcode != null
&& scanned_barcode.equalsIgnoreCase(barcode))) {
if ((!barcodeList.contains(barcode))) {
// if barcode I entered does not contains in the list
// It is working fine
barcodeList.add(barcode);//barcodeList contains only barcode
}
else if (barcodeList.contains(barcode)) {
data = list.get(barcodeList.indexOf(barcode));
// here is the problem
// here I want to get data of the barcode that have similar area and
location
if (data.getArea() == selected_area
&& data.getLocation() == selected_loc) {
doSomething();
} else {
doSomethingElse();
}
}
什麼是'barcodeList'的數據類型 –
我真的不知道你想要什麼。你想搜索並顯示到你的列表視圖或只是用'for'循環搜索? –