How to programmatically change the height of a list item after filling out a list

I am working on a news list. My list is one Activitythat expands ListActivity. I also created ArrayAdapterwhich I use to inflate the elements of my list. ArrayAdapteruses a simple layout with ImageViewand two TextViews. Everything works, but when I override the method onListItemClick()and try to resize the list items, when I click on them, nothing happens.

protected void onListItemClick(ListView l, View v, int position, long id) {
    v.getLayoutParams().height=300;
}

I tried above with LayoutParamsas well

Here is the layout of each line that I use to populate my list:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:background="@color/white"
     >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="4dp"
        android:src="@drawable/ic_launcher" >
    </ImageView>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    <TextView
        android:id="@+id/title1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textColor="@color/black"
        android:textColorHint="@color/black"
        android:textSize="10dp"
        android:textStyle="bold" >

    </TextView>  

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textColor="@color/black"
        android:textColorHint="@color/black"
        android:textSize="10dp" >

    </TextView>
    </LinearLayout>

</LinearLayout> 

Has anyone encountered the same problem? Can anyone bring in light for a newbie on Android?

+5
source share
1

, , , .

arrayAdapter, rowlayout, :

public class MySimpleArrayAdapter extends ArrayAdapter<String> {
    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;
    }
} 

ListActivity, json asynctask. onPostExecute AsyncTask .

onListItemClick:

    @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();
    }
}

requestLayout, .

+6

All Articles