Это мой код. Я здесь создаю представление списка с некоторыми данными массива. Когда я попадаю в список, я могу обнаружить его с помощью Toast. Но я не могу вызвать другое действие. вместо события Toast.
открытый класс ListView extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.foodjoint, RESTAURANTS));
android.widget.ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
myClickHandler();
}
});
// ListView restuList=ListView();
}
static final String[] RESTAURANTS = new String[] {
"Restaurant 1", "Restaurant 2", "Restaurant 3", "Restaurant 4", "Restaurant 5",
"Restaurant 6", "Restaurant 7", "Restaurant 8", "Restaurant 9", "Restaurant 10",
"Restaurant 11", "Restaurant 12", "Restaurant 13", "Restaurant 14", "Restaurant 15"
};
public void myClickHandler() {
finish();
Intent gotoLIst=new Intent(ListView.this,MenuActivity.class);
startActivity(gotoLIst);
}
а вот мой файл xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/AliceBlue "
android:padding="10dp"
android:textSize="16sp"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false" >
I need to call another activity @ listView onitemClick.
На самом деле я использовал другое действие, которое также использует некоторый список-представление, и это действие содержит некоторую ошибку. Вот почему оно не работает. Спасибо Luksprog за помощь в поиске ответа.