我有一个列表视图在某些版本的android中工作正常,但在棒棒糖中,列表视图不显示所有信息(只有1个字符串为5)。在我的应用程序中,我只有一个扩展AppCompatActivity的活动,这里是我的适配器
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>
答案 0 :(得分:1)
在棒棒糖中,我们需要设置字符串的颜色,因为它会自动将其设置为白色,因此我无法看到对象中的所有字符串。
对不起我的英语,这不是我的母语
答案 1 :(得分:0)
发布home_promo_item,可能你的LinearLayout是HORIZONTAl,而它应该是VERTICAL来显示ListView中的行。