Change this
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_fruit, FRUITS);
to
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, FRUITS);
You have
setContentView(R.layout.list_fruit); // list_fruit.xml
and you use the same in the ArrayAdapter
Also change
ListView listView = (ListView) findViewById(R.layout.list_fruit);
to
ListView listView = (ListView) findViewById(R.id.listview);
Also change to
Toast.makeText(getApplicationContext(),FRUITS[postion], Toast.LENGTH_SHORT).show();
Edit: list_fruit.xml
does not have a ListView.
You need the below in list_fruit.xml
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Then in onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_fruit);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, FRUITS);
ListView listView = (ListView) findViewById(R.id.listview);
listView.setTextFilterEnabled(true);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),FRUITS[postion], Toast.LENGTH_SHORT).show();
}
});
}