Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This was my getView() method.</p> <h2>main.xml</h2> <p> </p> <pre><code>&lt;ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_below="@+id/button1" android:cacheColorHint="@android:color/transparent" android:divider="#00ff00" android:fastScrollEnabled="true" android:focusable="false" android:listSelector="#000000" android:paddingTop="5dp" android:saveEnabled="true" &gt; &lt;/ListView&gt; </code></pre> <p></p> <h2>item.xml</h2> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;/LinearLayout&gt; </code></pre> <h2>Adapter</h2> <pre><code> class CustomAdapter extends ArrayAdapter&lt;String&gt; { public CustomAdapter(Context context, int resource, List&lt;String&gt; objects) { super(context, resource, objects); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; /*convertView = mInflater.inflate(R.layout.item, null); holder = new ViewHolder(convertView); convertView.setTag(holder); holder = (ViewHolder) convertView.getTag(); holder.getAppName().setText(str.get(position));*/ if(position==0) { ImageView iv = new ImageView(getApplicationContext()); iv.setBackgroundResource(R.drawable.ic_launcher); convertView = iv; } else if(position==1) { TextView tv = new TextView(getApplicationContext()); tv.setText("text view"); convertView = tv; } else { EditText et = new EditText(getApplicationContext()); et.setText("ET go home"); convertView = et; } return convertView; } private class ViewHolder { private View pathRow; private TextView appNameView = null; public ViewHolder(View row) { pathRow = row; } public TextView getAppName() { if (null == appNameView) { appNameView = (TextView) pathRow.findViewById(R.id.tv); } return appNameView; } } } </code></pre> <p>The commented out portion is the one used to be. The code below it is the one which I used to dynamically generate the view and return them. my listitem.xml still has a textView in it. But the adapter sets the view which we are returning from getView(). This works for me.</p> <p>I really don;t see the point of the LinearLayout in your item.xml. You can do that in your own code.</p>
 

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