I have a listview embed in a spinner within the onCreate method. I want to fire a toast msg on the list items on click event but can’t set up the onClick listener on the ListView items. I’m not using any custom adapters. I guess the same type of simple adapter is used for both the spinner and the listview therefore it generates some compiling frustrations.
I keep focused on the error obtained for "lv.setOnItemClickListener(new AdapterView.OnItemClickListener” :
The type new AdapterView.OnItemClickListener(){} must implement the
inherited abstract method
AdapterView.OnItemClickListener.onItemClick(AdapterView, View, int,
long)
How to manage to setup that click event on the listview items keeping using simple adapters ?
Shall I somehow “rename” the listview adapter or how to proceed then .. ?
Pseudo code
// ...
import android.widget.AdapterView;
/* manually added */
import android.widget.AdapterView.OnItemClickListener;
public class MyActivity extends Activity {
onCreate(Bundle savedInstanceState){
// ... some code
// Set Spinner listener
mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> spinner, View v, int position, long id) {
// ... some code
lv.setOnItemClickListener(new AdapterView.OnItemClickListener()) {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), "some msg" , Toast.LENGTH_SHORT).show();
}
});
}
}
So I have a spinner and a list view in the same activity. Based on the spinner selection, I update a listview. I also update the same listview from other events like button events for example. The code principle is as described in the question.
I confirm this way works perfectly and I solved my problem that had ntg to do with the spinner/ListView interactions but with the way I fetched data to feed the list.
To illustrate a bit the result, my layout looks similiar to this but with buttons additional to the spinner, both of them driving the listview result.