I have a listview with corresponding activities that start when you click on each item. But when I implement setTextFilterEnabled(true), the results, when clicked, do not start the correct activity. I read something about not using ‘position’, but what does that mean? How do I correct this?
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);}
}
}
}
The solution is simple, found it after hounding around the internet.
Just add:
inside the onItemClickListener