得到过滤列表视图原始ID [英] Get original ID from filtered Listview
问题描述
我在哪里,我可以把一个字符串数组类,它显示了一个搜索框来筛选内容的列表。我的应用程序很容易,每一个领域都有一组ID。然而,当我搜索一个值时,IDS变成过滤列表。有没有办法摆脱原始列表中的ID,这样即使在过滤列表,我可以有ID,如9,14,而不是0,1,2 ....
lv1.setAdapter(新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_1,searchItems));
ed.addTextChangedListener(新TextWatcher(){ 公共无效afterTextChanged(编辑S){
} 公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数,
INT后){
} 公共无效之前onTextChanged(CharSequence中,诠释开始,诠释,
诠释计数){ 。=长度限制:Textlength ed.getText()长();
arr_sort.clear();
的for(int i = 0; I< searchItems.length;我++){
如果(长度限制:Textlength&下; = searchItems [I]。长度()){
如果(ed.getText()。的toString()。equalsIgnoreCase((字符串)searchItems [I] .subSequence(0,长度限制:Textlength))){
arr_sort.add(searchItems [I]);
}
}
} lv1.setAdapter(新ArrayAdapter<串GT;(Rest_Search.this,android.R.layout.simple_list_item_1,arr_sort));
// lv1.smoothScrollToPosition(20);
}
});
lv1.setOnItemClickListener(新AdapterView.OnItemClickListener(){
@覆盖
公共无效onItemClick(适配器视图父母,视图V,
INT位置,长的id){
//字符串A = parent.getItemAtPosition(位置);
// MENUID =(int)的ID; INT A =(int)的parent.getAdapter()getItemId(位置)。
// MENUID =(INT)parent.getAdapter()getItemId(位置);
Toast.makeText(Rest_Search.this,+一,Toast.LENGTH_SHORT).show();
您可以自定义你的适配器
。创建一个新的类
扩展 BasaAdapter
并重写 getItemId
方法
@覆盖
众长getItemId(INT位置){
返回项目[位置] .getID();
}
,然后在 onItemClick
使用项目 ID
秒。
I have a class in where I can put in a StringArray, and it shows the list with a search box to filter contents. My application is prone that every field has a set ID. However, when I search for a value, the ids change into the filtered list. Is there a way to get the id from the original list, so that even in the filtered list I can have ids like 9, 14 instead of 0, 1, 2....
lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , searchItems));
ed.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textlength = ed.getText().length();
arr_sort.clear();
for (int i = 0; i < searchItems.length; i++) {
if (textlength <= searchItems[i].length()) {
if (ed.getText().toString().equalsIgnoreCase((String) searchItems[i].subSequence(0, textlength))) {
arr_sort.add(searchItems[i]);
}
}
}
lv1.setAdapter(new ArrayAdapter<String>(Rest_Search.this, android.R.layout.simple_list_item_1, arr_sort));
// lv1.smoothScrollToPosition(20);
}
});
lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View v,
int position, long id) {
// String a = parent.getItemAtPosition(position);
// menuID = (int) id;
int a = (int) parent.getAdapter().getItemId(position);
// menuID = (int) parent.getAdapter().getItemId(position);
Toast.makeText(Rest_Search.this, ""+a, Toast.LENGTH_SHORT).show();
You can customize your adapter
. create a new Class
extends BasaAdapter
and Override the getItemId
method:
@Override
public long getItemId(int position) {
return items[position].getID();
}
and then in onItemClick
use item id
s.
这篇关于得到过滤列表视图原始ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!