0

Here is the code of my custom adapter... it doesn't call my get view... returns only white blank page without nothing. I don't know what is the problem. Does anybody can help. Thanks a lot previously!

   public class ProductShopsAdapter extends ArrayAdapter<ProductShop> {

    private Context cntx;
    private ArrayList<ProductShop> shopValues;
    ProductShopsHolder holder = null;


    public ProductShopsAdapter(Context context, int textViewResourceId,  ArrayList<ProductShop> stringValues) {
        super(context,textViewResourceId);
        shopValues = stringValues;
        cntx = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            holder = new ProductShopsHolder();  

            LayoutInflater layoutInflater = (LayoutInflater)cntx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.shops_list, null);

            //Holder Elements initialization
            holder.setShopName((TextView)convertView.findViewById(R.id.shop_name));
            holder.setPrice((TextView)convertView.findViewById(R.id.shop_part_price));

            convertView.setTag(holder);
        } else {
            holder = (ProductShopsHolder) convertView.getTag();
        }
        holder.getShopName().setText(getItem(position).getShopName());
        holder.getPrice().setText(getItem(position).getPrice());

        return convertView;
    }
}

and here is my XML

 <?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ProductShopsActivity" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/footer"
        android:padding="0dp" >
    </ListView>

    <include
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@android:id/list"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        layout="@layout/footer_menu" />

</RelativeLayout>

and single view :

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_item"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#f2f2f2"
    android:orientation="horizontal"
    android:padding="10dp" >

    <TextView
        android:id="@+id/shop_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Technomarket"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/shop_part_price"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="30 лв."
        android:textSize="18sp" />

    <TextView
        android:id="@+id/details_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableRight="@drawable/rightarrow"
        android:gravity="center"
        android:text="Детайли"
        android:textColor="#289bd6"
        android:textSize="14sp" />

4

1 回答 1

4

您不需要ArrayList在您的内部ArrayAdapter-ArrayAdapter可以存储物品本身。这就是为什么getView()不被调用 - 默认实现getCount()返回ArrayAdapter本身的项目数。如果你把你的物品放在你自己的ArrayList,至少要覆盖getCount()返回shopValues.getCount()。否则,它始终为 0,ListView并且您的适配器绑定到的 甚至根本不知道有任何要显示的项目。

于 2013-09-02T07:33:51.357 回答