我有一个列表视图,其中包含您点击每个项目时开始的相应活动。但是当我实现setTextFilterEnabled(true)时,单击结果时,不会启动正确的活动。我读到了一些关于不使用“位置”的内容,但这意味着什么?我该如何纠正?
public class Contactpage extends ListActivity {
private static final int KEYBOARD = 0;
public void onCreate(Bundle savedInstanceState) {
String[] people = getResources().getStringArray(R.array.people_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.listtest, people));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
final String[] email = getResources().getStringArray(R.array.details_array);
final String[] number = getResources().getStringArray(R.array.number_array);
//Intent after selection is made
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String contenttt = email[position];
String contentt = number[position];
Intent showContent = new Intent(getApplicationContext(),
Viewer.class);
Bundle b = new Bundle();
b.putString("name",contenttt);
showContent.putExtras(b);
Bundle a = new Bundle();
a.putString("number",contentt);
showContent.putExtras(a);
startActivity(showContent);
}});}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, KEYBOARD, 0, R.string.menu_keyboard)
.setIcon(android.R.drawable.ic_menu_search);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case KEYBOARD: {
InputMethodManager imm = (InputMethodManager)
Contactpage.this.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null){
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
return true;}
default: {
return super.onOptionsItemSelected(item);}
}
}
}
答案 0 :(得分:0)
解决方案很简单,在互联网上追赶后找到它。 只需添加:
String name = lv1.getItemAtPosition(position).toString();
for (int index = 0; index < people.length; index++)
{
if (name.equals(people[index]))
{
position = index;
break;
}
}
在onItemClickListener
中