I rewrote the code and noticed I had the id wrong so changed it to theListView but I'm still getting errors... :(
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] Categories = {"Abstract", "Android", "Apple", "Animals", "Cartoons", "Celebrities",
"Girls", "Holidays", "Marvel", "Nature", "Sports", "Vehicles"};
ListAdapter theAdapter = new ArrayAdapter<String>(this, R.layout.row_layout, Categories);
ListView theListView = (ListView) findViewById(R.id.theListView);
theListView.setAdapter(theAdapter);
theListView.setOnItemClickListener(new parent.OnItemClickListener() {
@Override
public void onItemClick(parent<?> parent, View view, int position, long id) {
String categoryPicked = "You Selected " +
String.valueOf(parent.getItemAtPosition(position));
Toast.makeText(MainActivity.this, categoryPicked, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void (onItemClick(parent<?>parent, View view, int position, long id);
{
String CategoryPicked = "You selected " + String.valueOf(parent.getItemAtPosition(position));
Toast.makeText(MainActivity.this, CategoryPicked, LENGTH_SHORT).show();
}
change
String CategoryPicked = "You selected " + String.valueOf(adapterView.getItemAtPosition(position));
to :
String CategoryPicked = "You selected " + String.valueOf(parent.getItemAtPosition(position));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.