0

I'm writing an app the gets information off an RSS feed, parses it using the DOM parser (issues with the clients RSS feed) and then shows the parsed objects in a ListView.

For some reason, the getView() is not being called...

here is the code for the Activity:

public class NoPicList extends Activity {
    ListView list;
    NoPicAdapterV2 adapter2;
    ProgressDialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.no_pic_list);
        list = (ListView) findViewById(R.id.noPicListView);

        // get the request from the main activity
        Bundle b = getIntent().getExtras();
        String request = b.getString("REQUEST");

        mDialog = new ProgressDialog(this);
        mDialog.setCancelable(false);
        mDialog.setMessage("Lodaing Data");
        mDialog.show();

        new GetNewsAndCalendar().execute(request);
    }

    @Override
    protected void onPause() {
        mDialog.dismiss();
        super.onPause();
    }

    class GetNewsAndCalendar extends
        AsyncTask<String, Void, ArrayList<Message>> {

        @Override
        protected ArrayList<Message> doInBackground(String... params) {
            String url = params[0];
            DOMFeedParser parser = new DOMFeedParser(url);
            return parser.parse();
        }

        @Override
        protected void onPostExecute(ArrayList<Message> result) {
            adapter2 = new NoPicAdapterV2(NoPicList.this, R.layout.no_pic_list_item, result);
            list.setAdapter(adapter2);
            mDialog.dismiss();
            }

    }

}

here is the code for the adapter:

public class NoPicAdapterV2 extends ArrayAdapter<NewAndCalendar> {
    private ArrayList<Message> data;
    private LayoutInflater inflator;
    private Activity mActivity;

    public NoPicAdapterV2(Context context, int textViewResourceId,
        ArrayList<Message> result) {
        super(context, textViewResourceId);
        data = (ArrayList<Message>) result;
        mActivity = (Activity) context;
        inflator = (LayoutInflater) mActivity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        if (vi == null)
            vi = inflator.inflate(R.layout.no_pic_list_item, parent, false);

        TextView title = (TextView) vi.findViewById(R.id.noPicTitle);
        TextView subtitle = (TextView) vi.findViewById(R.id.noPicSubtitle);
        TextView id = (TextView) vi.findViewById(R.id.noPicID);

        title.setText(data.get(position).getTitle().toString());
        subtitle.setText(data.get(position).getDate().toString());
        id.setText(data.get(position).getDescription());

        return vi;
    }
}

the DOMFeedParser code is built according to the IBM open source Java XML parser article.

thanks a bunch...

4
  • what about result.size() in onPostExecute? Commented Apr 19, 2012 at 10:03
  • may be because the list count is 0.. i mean the data is empty. Commented Apr 19, 2012 at 10:03
  • do your result contains data in onPostExecute? Commented Apr 19, 2012 at 10:05
  • the result comes back filled with data, I double-checked that before posting the question Commented Apr 19, 2012 at 10:08

3 Answers 3

3

you should override (in your custom adapter)

getCount()

and return the size of data in order to let the adpater works. Or you call the ArrayAdapter constructor that takes data

public ArrayAdapter (Context context, int textViewResourceId, T[] objects)
Sign up to request clarification or add additional context in comments.

4 Comments

well, I overrode the function, and now getView() IS being called. but the view that is being displayed is not the full list but a list_item. So I changed the constructor calling from adapter2 = new NoPicAdapterV2(NoPicList.this, R.layout.no_pic_list_item, result); to R.layout.no_pic_list that is, of course, the list and not the list item, however, still nothing happened...
The listview will contain the number of entry equals a data.size(). I do not understand what you mean in your comment
the easiest is to give the super the array. there is no point in keeping a local reference to the array in an arrayadapter, as the super already does it
it easy override too. Then, if you read the whole answer i already told him to use the other constructor
0

Your ArrayAdapter does not know the content of your array, and therefore the count is 0.

Use this super constructor instead : http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter%28android.content.Context,%20int,%20java.util.List%3CT%3E%29

Like this :

public NoPicAdapterV2(Context context, int textViewResourceId,
    ArrayList<Message> result) {
    // Here
    super(context, textViewResourceId, result);
    data = (ArrayList<Message>) result;
    mActivity = (Activity) context;
    inflator = (LayoutInflater) mActivity
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

Comments

0

I hope below code will work just add one more argument to super(...)

public NoPicAdapterV2(Context context, int textViewResourceId,
        ArrayList<Message> result) {
        super(context, textViewResourceId,result);
        data = (ArrayList<Message>) result;
        mActivity = (Activity) context;
        inflator = (LayoutInflater) mActivity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.