Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hi guys I finally found a solution to my problem and I would like to share it with the rest of the community. </p> <p>I'm using an arrayAdapter to inflate my rowlayout following is it's code:</p> <pre><code>public class MySimpleArrayAdapter extends ArrayAdapter&lt;String&gt; { private final Context context; private final String[] values; private final Bitmap[] images; private final String[] names; public MySimpleArrayAdapter(Context context, String[] values, Bitmap[] images, String [] names) { super(context, R.layout.rowlayout, values); this.context = context; this.values = values; this.images=images; this.names=names; } View rowView; @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); //View rowView; rowView = inflater.inflate(R.layout.rowlayout, parent, false); TextView textView = (TextView) rowView.findViewById(R.id.label); ImageView imageView = (ImageView) rowView.findViewById(R.id.icon); TextView title=(TextView) rowView.findViewById(R.id.title1); textView.setText(values[position]); imageView.setImageBitmap(images[position]); title.setText(names[position]); return rowView; } } </code></pre> <p>My main activity extends ListActivity where the items for the list are fetched from some json files in an asynctask. In the onPostExecute method of AsyncTask my list is created with the fetched items.</p> <p>Following is the code for the onListItemClick method:</p> <pre><code> @Override protected void onListItemClick(ListView l, View v, int position, long id) { int hei=v.getLayoutParams().height; System.out.println("Height "+hei); if (hei==LayoutParams.WRAP_CONTENT) { v.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,105)); v.requestLayout(); } else { v.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); v.requestLayout(); } } </code></pre> <p>The trick is to call the requestLayout method so that your layout is refreshed.</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