我有一個列表視圖,在Android的某些版本中工作正常,但在棒棒糖列表視圖不顯示所有信息(只有1個字符串5)。在我的應用我只是AppCompatActivity的延伸的活動,在這裏我的適配器ListView棒棒糖不顯示所有信息
public class PromoAdapter extends ArrayAdapter {
private Context context;
private ArrayList<PromoObject> originalData = null;
public PromoAdapter(Context context, ArrayList<PromoObject> listArray) {
super(context, R.layout.home_promo_item);
this.context = context;
this.originalData = listArray ;
}
public static class Row
{
public TextView labelPromo;
public ImageView imagePromo;
public TextView titlePromo;
public TextView daysPromo;
public TextView schedulePromo;
}
@Override
public int getCount() {
return originalData.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// reuse views
if (rowView == null) {
LayoutInflater inflater = LayoutInflater.from(context);
rowView = inflater.inflate(R.layout.home_promo_item, null);
// configure view holder
Row viewHolder = new Row();
viewHolder.labelPromo = (TextView) rowView.findViewById(R.id.label_promo);
viewHolder.imagePromo = (ImageView) rowView.findViewById(R.id.logo_promo);
viewHolder.titlePromo = (TextView) rowView.findViewById(R.id.title_promo);
viewHolder.daysPromo = (TextView) rowView.findViewById(R.id.days_promo);
viewHolder.schedulePromo = (TextView) rowView.findViewById(R.id.schedule_promo);
rowView.setTag(viewHolder);
}
Row holder = (Row) rowView.getTag();
PromoObject itm = originalData.get(position);
holder.labelPromo.setText(itm.getPromoValue());
holder.imagePromo.setImageResource(R.drawable.ic_pizzahut);
holder.titlePromo.setText(itm.getTitlePromo());
holder.daysPromo.setText(itm.getDays());
holder.schedulePromo.setText(itm.getSchedule());
return rowView;
}
}
這裏MI XML文件:home_promo_item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<RelativeLayout
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignBottom="@+id/box_info"
android:background="@color/promo_1"
android:id="@+id/box_promo">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-25%"
android:textColor="@color/white"
android:gravity="right"
android:textSize="20sp"
android:id="@+id/label_promo"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:layout_marginLeft="25dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/box_promo"
android:id="@+id/box_info"
android:layout_toEndOf="@+id/box_promo"
android:background="@drawable/border_right">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="@drawable/ic_pizzahut"
android:padding="10dp"
android:id="@+id/logo_promo"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/logo_promo"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title_promo"
android:gravity="center"
android:text="EN TODAS NUESTRAS PIZZAS"
android:layout_marginTop="1dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/days_promo"
android:text="Promoción Valida de Lunes a Jueves"
android:layout_below="@+id/title_promo"
android:gravity="right"
android:layout_alignRight="@+id/title_promo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/schedule_promo"
android:text="de 12:00 m a 5:00pm."
android:layout_below="@+id/days_promo"
android:layout_alignRight="@+id/days_promo" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Post home_promo_item。 –
Post ListView項目XML佈局。您的ViewHolder是不必要的 –
home_promo_item準備好了! @dieter_h –