在Android的Alertdialog中设置列表视图

问题描述 投票:0回答:1

在alertdialog中具有列表视图。而customlistview有一个spearate适配器类。问题是值在列表中,但没有显示在列表视图中。当我在平板电脑中运行时,其中有一个空行。下面是我的代码。我不认为适配器有错误。请问任何解决方案吗?

我的适配器:

public class Mse_LotAdapter extends ArrayAdapter<MSE_Lotno>  implements Filterable{

    List<MSE_Lotno> list;

    List<MSE_Lotno> filterlst;
    // = new ArrayList<MSE_OrderDetails>();
    Context context;

    TextView txtLotnum;
    TextView txtLotqty;

    private ModelFilter filter;

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

    public Mse_LotAdapter(Context context, List<MSE_Lotno> value) {
        // TODO Auto-generated constructor stub
        super(context, R.layout.twotextview, value);
        this.context = context;
        this.list = value;

        this.filterlst=new ArrayList<MSE_Lotno>(list);
        getFilter();
    }

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

        final int pos = position;

        View view = null;
        if (convertView == null) {

            convertView = LayoutInflater.from(getContext()).inflate(
                    R.layout.twotextview, parent, false);

            txtLotnum = (TextView) convertView.findViewById(R.id.txt_lotnum);
            txtLotqty = (TextView) convertView.findViewById(R.id.txt_lotqty);

            convertView.setTag(new OrdersViewHolder(txtLotnum, txtLotqty));


        } else {
            OrdersViewHolder viewHolder = (OrdersViewHolder) convertView
                    .getTag();
        }

        OrdersViewHolder holder = (OrdersViewHolder) convertView.getTag();

        holder.txtLotnum.setText(list.get(position).getLotNo());
        holder.txtLotqty.setText(list.get(position).getLotQty());

        return convertView;

    }

    /** Holds child views for one row. */
    static class OrdersViewHolder {

        TextView txtLotnum;
        TextView txtLotqty;


        public OrdersViewHolder(TextView txtLotnum, TextView txtLotqty) {
            // TODO Auto-generated constructor stub
            this.txtLotnum = txtLotnum;
            this.txtLotqty = txtLotqty;


        }



        public TextView getTxtitem() {
            return txtLotnum;
        }

        public void setTxtitem(TextView txtLotnum) {
            this.txtLotnum = txtLotnum;
        }

        public TextView getTxtdesc() {
            return txtLotqty;
        }

        public void setTxtdesc(TextView txtdesc) {
            this.txtLotqty = txtdesc;
        }


    }

    private class ModelFilter extends Filter {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {

            constraint = constraint.toString().toLowerCase();
            FilterResults result = new FilterResults();
            if (constraint != null && constraint.toString().length() > 0) {
                ArrayList<MSE_Lotno> filteredItems = new ArrayList<MSE_Lotno>();

                for (int i = 0, l = list.size(); i < l; i++) {
                    MSE_Lotno customer = list.get(i);
                    String strNum = customer.getOrderNo();//tHhCustomer_number();

                    if (strNum.toLowerCase().contains(constraint))//|| strName.toLowerCase().contains(constraint))
                        filteredItems.add(customer);
                }
                result.count = filteredItems.size();
                result.values = filteredItems;
            } else {
                synchronized (this) {
                    result.values = list;//ModelItemsArray;
                    result.count = list.size();
                }
            }
            return result;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint,
                                      FilterResults results) {

            filterlst = (ArrayList<MSE_Lotno>) results.values;
            notifyDataSetChanged();
            clear();
            for (int i = 0, l = filterlst.size(); i < l; i++)
                add(filterlst.get(i));
            notifyDataSetInvalidated();
        }
    }

}

我的AlertDialog:

    LayoutInflater li = LayoutInflater.from(MseItemList.this);
                    View promptsView = li
                            .inflate(R.layout.mse_shipment_entry, null);

                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                            MseItemList.this);
                    alertDialogBuilder.setView(promptsView);

                    if (qtyOrderd != 0 && qtyOrderd > 0) {
                        btnExit.setVisibility(view.GONE);

                        // create alert dialog
                        final AlertDialog alertDialog = alertDialogBuilder.create();

                        alst = new ArrayList<String>();// initialize array list

                        edt_itemNo = (EditText) promptsView
                                .findViewById(R.id.edt_mseshipItemNo);


                        lstLotnum = (ListView) promptsView.findViewById(R.id.lst_lotnum);

                        dbhelper.getReadableDatabase();
                        lotList = dbhelper.getTempItems();
                        dbhelper.getWritableDatabase();
                        adapter = new Mse_LotAdapter(MseItemList.this,lotList);
                        lstLotnum.setAdapter(adapter);
         }
alertDialog.show();
    }

布局:

 <LinearLayout
        android:id="@+id/layLotList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/layDesc"
        android:layout_gravity="center"
        android:layout_marginLeft="3dp"
        android:layout_marginTop="16dp"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/listTitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:background="#267ad4"
            android:orientation="horizontal"
            android:padding="5dp" >

            <TextView
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:text="Lot No"
                android:textSize="24sp"
                android:textStyle="bold" >
            </TextView>

            <TextView
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:gravity="center|right"
                android:text="Qty"
                android:textSize="24sp"
                android:textStyle="bold" >
            </TextView>

        </LinearLayout>

       <ListView
           android:id="@+id/lst_lotnum"
           style="@style/ListViewAppTheme.White"
           android:layout_width="match_parent"
           android:layout_height="200dp">
       </ListView>



    </LinearLayout>
android android-alertdialog
1个回答
0
投票

您的LinearLayout的方向是水平的。因此您的列表视图除了第一个linealayout(具有标题)之外。

只需将LinearLayout(layLotList)的方向更改为垂直,它将显示listview。

至少它将显示listview,然后您可以检查其样式和listitem的xml文件以设置其设计。

© www.soinside.com 2019 - 2024. All rights reserved.