Q:

Android listview - listener must override superclass method

here's the code, I have problem with:
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, android.view.View view,
                int position, long id) {

            if(listview.isItemChecked(position)){

            } 

            if(listview.getCheckedItemCount()>1){

            }

        }
    });

it keeps saying that listener must override superclass method and that I cant call non-final variable "listview" inside inner class. how am I supposed to call listview.isItemChecked(position) then? thanks

A:

I'd suggest you read up on the use of final in Java. Technically, you could fix this by adding the keyword final before ListView listview = ..., so final ListView listview = ....
However, a better option is to just use the passed reference to ListView in your OnItemClick-method. The parameter AdapterView<?> Parent corresponds to your ListView, so you can use the following code:
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, android.view.View view,
            int position, long id) {

        ListView lv = (ListView) parent;

        if(lv.isItemChecked(position)){
            // ...
        } 

        if(lv.getCheckedItemCount()>1){
            // ...
        }

    }
});

