2014-11-02 28 views
0

我有一个应用程序,其中包含一个SQLite数据库和一个使用SimpleCursorAdapter映射数据库的ListView。我使用TextWatcher读取带有条形码扫描器的字符串。现在我想在ListView中挑选扫描的字符串,并将相关的行放在顶部。因此,我认为我需要排的位置。我怎样才能在ListView中获取扫描字符串的位置?或者还有其他方法来管理它吗?如何在不使用OnItemClickListener的情况下获取ListView中某行的位置

+0

你可以从你的适配器做到这一点 – 2014-11-02 12:11:51

回答

0
//mAdapter is your listview adapter 
public int getRowInListView(String barcodedString){ 
    for(int i = 0; i < mAdapter.getCount(); i++){ 
     String s = mAdapter.getItem(i).toString(); 
     //if you have a custom object in you adapter instead use this 
     String s = ((MyObject)mAdapter.getItem(i)).getBarcode(); 

     if(s.equals(barcodedString)) 
      return i; 
    } 

    return -1 
} 
+0

就是这样。谢谢! – Schnicke 2014-11-02 13:16:41

相关问题