简体   繁体   中英

Can I populate a listview from getView of a custom adapter?

I have a listview that contains items that have listviews. I am trying to populate item's listviews from inside the getView of the custom adapter that populates the "parent" listview:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    System.out.println("session adapter: here1");
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        v = inflater.inflate(R.layout.single_session, null);


    }

    SessionObject i = sessions.get(position);

     if (i != null) {
         tvTrackName = (TextView) v.findViewById(R.id.textViewTrackName);
         tvTrackName.setText(i.trackName);
         tvSessionName = (TextView) v.findViewById(R.id.textViewSessionName);
         tvSessionName.setText(i.sessionName);

         tvSessionModerator = (TextView) v.findViewById(R.id.textViewModeratorName);
         tvSessionModerator.setText("Moderator: "+i.sessionModerator);

         listAbstracts = i.abstractList;

         lvAbstracts = (ListView) v.findViewById(R.id.listViewAbstracts);

         AbstractObjectAdapter adapter = new AbstractObjectAdapter(act, R.id.listViewAbstracts, listAbstracts);
         lvAbstracts.setAdapter(adapter);  
      }
     return v;  

}

The "interior" adapter seems to only be calling its getView function once, regardless of the number of items in its list. If there are 2 items, only the first gets put into the listview. Is this the wrong way to do this? Am I missing something?

Any help is appreciated. Thanks.

Just create your item view dynamically, adding textviews to a linearlayout. You'll just have to be careful about handling the convertView, initially it will be easiest to always ingore it but you'll take a bit of a performance hit.

Optimise later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM