1

Hi my android app has a listactivity this activity called from another activity with Intent , after calling in onCreate method of the ListActivity create a new AsynchTask and call web service and put all stuff into my ArrayList data come from web service is fine , but when i try to implement getView of the customArrayAdapter things get wierd , it sometimes show content of the list sometimes not or sometimes when i scroll.Here is my getView method of custom adapter. (Layout = textview + listView)

class EntryDetailsAdapter extends ArrayAdapter<Entry>{

      private ArrayList<Entry> entryDetails;
      private Entry tempEntry;

      public EntryDetailsAdapter(Context context, int textViewResourceId,
        List<Entry> objects) {
       super(context, textViewResourceId, objects);
       // TODO Auto-generated constructor stub
       entryDetails =  (ArrayList<Entry>) objects;
      }

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
       // TODO Auto-generated method stub
       View mView = convertView;

       if(mView == null){

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.entry_rows, null);

       }

       tempEntry = entryDetails.get(position);
       //data is fine but problem is while occur while showing data

       if(tempEntry != null){
        //get the textview from list row xml that i defined
        TextView textView = (TextView) findViewById(R.id.entryRowTextView);
        if(textView != null){
        //i dont know why but this sometimes giving null so check
         textView.setText(tempEntry.getEntryContent());
        }
       }
       return mView;
      }
     }

[NOTE] Problem might similar to this question but i couldnt find a solution

Community
  • 1
  • 1
Burak Dede
  • 3,725
  • 5
  • 40
  • 53

2 Answers2

0

Since you said that your data to be shown in the list is pooled from the web service, is it possible that data is not loaded yet and you are already trying to access it? Are you waiting for data to be loaded from service before setting list adapter?

dstefanox
  • 2,222
  • 3
  • 19
  • 21
  • no result, after you said that i check with already pooled data , bu no lock , still showing list in a weird way , i suspect the problem is about getView method – Burak Dede Dec 18 '10 at 21:45
  • as dhaag23 said, you are missing TextView textView = (TextView)mView.findViewById(R.id.entryRowTextView) . Also, to get more efficient list, try using ViewHolder pattern – dstefanox Dec 18 '10 at 23:14
0

Try:

 TextView textView = (TextView)mView.findViewById(R.id.entryRowTextView);

you were missing the mView when getting the particular row's TextView field.

dhaag23
  • 6,106
  • 37
  • 35