سؤال

    protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        // updating UI from Background Thread
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * Updating parsed JSON data into ListView
                 * */


                ListAdapter adapter = new SimpleAdapter(
                        getActivity(), inboxList,
                        R.layout.inbox_list_item, new String[] { TAG_LINK, TAG_SUBJECT },
                        new int[] { R.id.link, R.id.subject });
                // updating listview
                lv.setListAdapter(adapter);

                            lv.setOnItemClickListener(new OnItemClickListener() {

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

                        Toast.makeText(getActivity(), 
                                "You clicked on feed "+position, Toast.LENGTH_LONG).show();



                    }

                });

            }
        });

    }

Im trying to get a list view in a fragment activity. This list view is a parsed from JSON objects. This code runs in a fragment. However, setlistadapter gives an error. Any alternatives for setlistadapter and how to implement it. Thank you.

هل كانت مفيدة؟

المحلول

Use the Custom adapter Like this:

Listview list = (Listview)findviewbyId(R.id.list);
SearchListAdapter adapter = new SearchListAdapter(this,
                        getActivity(), rowItems(your data to inflate in adapter));
                lis.setAdapter(adapter);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top