Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this seems doable. I haven't tested this at all, but in theory you could get away with something like this:</p> <pre><code>public interface Adaptable { //Interface that any object you make that should be put in a listview //should implement public View buildView(View v, LayoutInflater inflater); public int getLayoutId(); } public class MyObject implements Adaptable //Just hardcode your layout for this type of object public int getLayoutId() { return R.layout.myLayout; } //getView() will pass the recycled view to this method //which will handle building the view per this object public View buildView(View v, LayoutInflater inflater) { if(v == null) { v = inflater.inflate(getLayoutId()); //Other initialization } //other initialization return v; } } //Then make the generic adapter that handles anything that implements //the Adaptable interface public GenericAdapter implements ListAdapter { private LayoutInflater inflater; private List&lt;Adaptable&gt; items; public GenericAdapter(List&lt;Adaptable&gt; items, Context c) { this.items = items; inflater = LayoutInflater.from(c); } //Now, using polymorphism, it should return a correctly built //view for whatever object type you've passed in. @Override public View getView(int pos, View convertView, ViewGroup parent) { return items.get(pos).buildView(convertView, inflater); } } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); List&lt;MyObject&gt; objects = new ArrayList&lt;MyObject&gt;(); //Fill your list however. //get your ListView, then... listView.setAdapter(new GenericAdapter(object, this)); } </code></pre> <p>It's possible I've totally overlooked some reason this wouldn't work -- I typed this up in five minutes. In theory I think it would work, though.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload