查看给定位置列表时不正确。如何传达我需要的位置? 方法 getItemId(位置)没有帮助! 有一些示例代码:
lv1 = (ListView) findViewById(R.id.list);
inputSearch = (EditText) findViewById(R.id.inputSearch);
final String listcode[] = getResources().getStringArray(R.array.list);
adapter = new ArrayAdapter<String>(this, R.layout.list_item,
R.id.product_name, listcode);
lv1.setAdapter(adapter);
lv1.setTextFilterEnabled(true);
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
long line = adapter.getItemId(position);
Integer itemname = new Integer((int) line);
Intent intent = new Intent();
intent.setClass(Main.this, ShowKnot.class);
Bundle b = new Bundle();
b.putString("defStrID", itemname.toString());
b.putString("defStrName", listcode[itemname]);
intent.putExtras(b);
startActivity(intent);
}
});
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
Main.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
答案 0 :(得分:1)
而不是
long line = adapter.getItemId(position);
你可以在方法中使用“位置”争论返回列表项位置编号
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
a.getItemAtPosition(position);
这里“int position”参数是listitem的索引。