Alex Rivera | Logout

Listview in android did not refresh the view until dragged

Asked 2011-07-18T11:31:29.263
9

I am using the code below:

private Runnable returnRes = new Runnable() {

        @Override
        public void run() {
            if(m_orders != null && m_orders.size() > 0){
                m_adapter.notifyDataSetChanged();
                for(int i=0;i<m_orders.size();i++)
                m_adapter.add(m_orders.get(i));
            }
            m_ProgressDialog.dismiss();
            m_adapter.notifyDataSetChanged();
        }
      };

but the weird thing is, after the list populates, the only item available is the first thing on the list the rows directly below would be empty unless I drag down out of view then back again then it'd show. I'm pretty sure the code above is right as I followed a tutorial. But, I cant expect the user to drag down and back again to see the things involved...

And to add, I just noticed that my datas are not populated properly as this warning would appear 07-19 23:54:49.947: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44eb97c0 and I'm quite sure that my codes are correct and the following is where it stops:

public View getView(int position, View convertView, ViewGroup parent){
    View v = convertView;
    if(v != null){
        return v;
    }
    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = vi.inflate(R.layout.row, null);

    Log.d("added", "g" + position);
    Grade g = grades.get(position);
    if(g != null){
        TextView name = (TextView) findViewById(R.id.bottomtext);
        TextView id = (TextView) findViewById(R.id.toptext);
        if(name != null)
            name.setText(g.getName());
        if(id != null)
            id.setText(g.getId());
        Log.d("grade", "grade " + g.toString());

    }

    return v;
}

and from the LogCat trace I would only get to position 3 :( w

Edit
Report

1 Answer

10

Try calling ListView.invalidateViews() on the list view. Worked for me.

Even if you call notifyDataSetChanged() and/or notifyDataSetInvalidated() from the UI thread on the adapter, these only invalidates the data and not the views. Hence.

answered 2011-11-04T22:08:14.503

Your Answer