多个ListView出现在android中

时间:2016-01-14 02:12:26

标签: java android listview android-listview

奇怪的是,我的活动中出现了多个listview。我正在试用My Nexus 5和Nexus 5x。

在nexus 5上 - 它只是一个。在nexus 5x上 - 没有限制。检查下图:这里可能出现的问题:

Nexus 5:只有一个Listview。

enter image description here

Nexus 5x - 显示多个列表视图:

enter image description here

这是我的XML文件(具体):

<RelativeLayout
                        android:id="@+id/recommendedLayout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/panelcolor"
                        android:layout_below="@+id/buttonbar"
                        android:visibility="gone"
                        android:orientation="vertical"
                        android:padding="5dp">

                        <com.neopixl.pixlui.components.textview.TextView
                xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
                            android:id="@+id/menuId1Text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/recommendedproduct"
                            android:textColor="@color/whitetext"
                            android:textSize="14sp"
                            pixlui:clearclipboardcontent="true"
                            pixlui:copyandpaste="false"
                            pixlui:typeface="robotoregular.ttf" />

</RelativeLayout>

<ListView
                        android:id="@+id/relatedProduct"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/recommendedLayout"
                        android:visibility="gone"
                        android:divider="@null">
</ListView>

ArrayAdapter:

public class RelatedProductListAdapter extends ArrayAdapter<ProductDetails>
{
    private final Context contextValue;
    private final SharedPreferences pref;
    private final String nonetwork;
    ArrayList<ProductDetails> productList;
    private ArrayList<ProductDetails> originalList;
    private ProductFilter filter;
    private LayoutInflater vi;
    private String productNametext;
    private String casevalue;

    public RelatedProductListAdapter(Context context, int textViewResourceId, ArrayList<ProductDetails> nameList)
    {
        super(context, textViewResourceId, nameList);
        this.productList = new ArrayList<ProductDetails>();
        this.productList.addAll(nameList);

        this.originalList = new ArrayList<ProductDetails>();
        this.originalList.addAll(nameList);

        vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        contextValue = context;

        pref = getContext().getApplicationContext().getSharedPreferences("MyPref", Context.MODE_PRIVATE);
        nonetwork = pref.getString("networkisavailable", getContext().getResources().getString(R.string.yesnetwork));

        //imageLoader = new ImageLoader(mContext);
    }

    private class ViewHolder
    {
        public TextView productName;
        public ImageView image;
        public TextView productCode;
    }

    @Override
    public Filter getFilter()
    {
        if (filter == null)
        {
            filter  = new ProductFilter();
        }
        return filter;
    }

    @Override
    public View getView(int position, View convertView, final ViewGroup parent)
    {
        ViewHolder mViewHolder;
        if (convertView == null)
        {
            convertView = vi.inflate(R.layout.giftlist_layout, null);
            mViewHolder = new ViewHolder();

            LinearLayout mainLinnerLayout = (LinearLayout) convertView
                    .findViewById(R.id.mainLinear);

            ProductDetails pd = productList.get(position);

            for (int i = 0; i < productList.size(); i++)
            {
                mainLinnerLayout.addView(getview(productList.get(i)));
            }


            convertView.setTag(mViewHolder);
    }
        mViewHolder = (ViewHolder) convertView.getTag();
            return convertView;
    }

    private View getview(final ProductDetails gitem)
    {
        View additionView = vi.inflate(R.layout.ozi_related_product, null, false);

        TextView productName1 = (TextView) additionView.findViewById(R.id.grid_item_label);
        SquareImageView image = (SquareImageView) additionView.findViewById(R.id.grid_item_image);

        productName1.setText(gitem.getName());

        Glide.with(getContext().getApplicationContext())
                .load(gitem.getImage())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                //.override(250, 250)
                .crossFade()
                .into(image);

        additionView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v)
            {

            }
        });

        return additionView;
    }


    private class ProductFilter extends Filter
    {

}

这很奇怪..有人可以帮我解决这个问题吗?

谢谢!

0 个答案:

没有答案