1.Check condition only display
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.main_alllatestnewslist, parent,
false);
ImageView imageview = (ImageView) vi
.findViewById(R.id.image_alllatestnewstitle);
imageview.setVisibility(View.INVISIBLE);
TextView titletext = (TextView) vi
.findViewById(R.id.text_particularlatestnewstitle);
TextView categorytext = (TextView) vi
.findViewById(R.id.text_newscategorytitle);
TextView datetext = (TextView) vi.findViewById(R.id.text_newsdate);
if (!imagepath[position].toString().equals("no picture")) {
imageLoader.DisplayImage(imagepath[position], imageview);
imageview.setVisibility(View.VISIBLE);
titletext.setWidth(460 - imageview.getWidth() - 5); <-- this line
} else {
imageview.setVisibility(View.INVISIBLE);
imageview.setImageDrawable(null);
}
titletext.setText(title[position].toString());
categorytext.setText(category[position].toString());
datetext.setText(date[position].toString());
return vi;
}
The statement cannot be check when first view of the list and causing the textview stack with imageview. After scroll one or more times it only move to left.
How to go in this statement before display it?
2. set all items’ height in listview programmatically base on condition
RelativeLayout childlayout = (RelativeLayout)vi.findViewById(R.id.layout_childlist);
This is the layout for an item.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_childlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/list_bg"
android:minHeight="?android:attr/listPreferredItemHeight" >
<LinearLayout
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="5px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginTop="5px" >
<ImageView
android:id="@+id/image_alllatestnewstitle"
android:layout_width="140px"
android:layout_height="80px"
android:scaleType="centerCrop" />
</LinearLayout>
....
</RelativeLayout>
For example, one of the item took 80px to display but the other items only took 40px. However, the other items will not wrap to 40px and wrap to 80px and make all the items has same height.
How to set the height for all items with difference height?
Try
imageview.setVisibility(View.GONE);INVISIBLEonly hides the view whileGONE‘removes’ it