Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnItemClickListener cannot be resolved to a type (inside Fragment)

This seems to be a common problem that is usually solved by adding the right imports. But in my case it doesn't seem to solve anything. I'm fairly new to programming especially in Android so bear with my foolish mistakes (if applicable).

I have the following imports and code and yet Eclipse keeps saying AdapterView.onItemClickListener cannot be resolved to a type. Any help would be much appreciated.

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public static class MainApplicationFragment extends Fragment {
    private ArrayAdapter<String> listAdapter;
    public MainApplicationFragment() {

    }

    private void PopulateWorkorderList() throws IOException {

        StorageAccess access = new StorageAccess();
        listAdapter = new ArrayAdapter<String>(getActivity(), R.layout.workorder_list_row);

        for (Workorder WO : access.GetAllWorkorders()) {
            listAdapter.add(WO.getWorkorderNumber().toString());
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        try {
            PopulateWorkorderList();
            ListView mainListView = (ListView) getView().findViewById( R.id.workorderList );
            mainListView.setAdapter(listAdapter);   
            mainListView.setOnItemClickListener(new AdapterView.onItemClickListener() {
                   public void onItemClick(AdapterView<> parent, View view, int position, long id) {
                          Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
                   }});
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           
    }   
}
like image 913
Hetiwos Avatar asked Nov 17 '14 14:11

Hetiwos


1 Answers

(new AdapterView.onItemClickListener() 

should be

(new AdapterView.OnItemClickListener() 

with capital O

like image 71
Blackbelt Avatar answered Oct 16 '22 20:10

Blackbelt