Question

I have an app that hits a REST service, gets some json and then places it into a listview. My main activity extends Activity and not ListActivity. I can scroll through the list items, but I cannot select any (at least by touch). I get to the listview through findViewBYId and have an adapter that extends SimpleAdapter. I have set the convertView inside the adapter's getVIew() as clickable. However when I do this, I can no longer click on the list items in the listView? Did I do this wrong?

public class App extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        jobsListView = (ListView) findViewById(R.id.jobs_list);
        jobsListView.setAdapter(new JobItemAdapter(jobsListView.getContext(), 
                jobsList, 
                R.layout.list_item, 
                new String[] {"title","location"},
                new int[] {R.id.job_title, R.id.job_location}));
        jobsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                Log.i("jobsListView.setOnItemClickListener()"," item clicked: " + arg0.getSelectedItemPosition());
            }

        });

    }

    public class JobItemAdapter extends SimpleAdapter {
        private List<HashMap<String,String>> jobsList;

        public JobItemAdapter(Context context, List<HashMap<String,String>> jobs, int resource, String[] from, int[] to)
        {   
            super(context, jobs, resource, from, to);
            jobsList = jobs;            
        }

        public View getView(int position, View convertView, ViewGroup parent){
            Log.i(TAG," in  JobItemAdapter getView() ");

            if (convertView == null) {
                //no previous views, inflate views
                convertView = getLayoutInflater().inflate(R.layout.list_item, parent, false);
            }

            //update textviews in layout
            TextView title = (TextView)convertView.findViewById(R.id.job_title);
            title.setText(jobsList.get(position).get("title"));

            TextView location = (TextView)convertView.findViewById(R.id.job_location);
            location.setText(jobsList.get(position).get("location"));
            //make the view clickable
            convertView.setClickable(true);
            return convertView;
        }

    }

}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top