如何以编程方式将滚动视图放入警报对话框

时间:2018-10-16 15:58:54

标签: java android-studio android-recyclerview scrollview android-alertdialog

我在将所有数据显示在最后显示的AlertDialog中时遇到问题。我尝试在AlertDialog中添加滚动视图,但是scrollview不显示,并且仍然显示最后一条记录,该记录实际上是所有数据超过第13行的数量。

TransactionActivity.java

 private void inputUser() {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            LinearLayout layout = new LinearLayout(this);
            layout.setOrientation(LinearLayout.VERTICAL);
            layout.setGravity(Gravity.CLIP_VERTICAL);
            layout.setPadding(30, 30, 30, 30);

            View view2 = getLayoutInflater().inflate(R.layout.books_list,null);



            final ScrollView scrollView = new ScrollView(this);

        //showing all data
            for (Books list : booksList) {
                String id = String.valueOf(list.getId());
                String Item_name = list.getItem_name();
                String Price = String.valueOf(list.getPrice());
                String file = list.getFile();

                final TextView txtId = (TextView) view2.findViewById(R.id.txtId);
                txtId.setText(id);

                final TextView txtItem_name = (TextView) view2.findViewById(R.id.txtItem_name);
                txtItem_name.setText(Item_name);


                final TextView txtPrice = (TextView) view2.findViewById(R.id.txtPrice);
                txtPrice.setText(Price);

                final ImageView img = (ImageView) view2.findViewById(R.id.file);
                Picasso.with(this).load(URI_SEGMENT_UPLOAD + file).into(img);

            }

            scrollView.addView(view2);
            builder.setView(scrollView);
            builder.setTitle("PRODUCTS LIST");

            builder.setCancelable(false);
            builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });


            final AlertDialog dialog = builder.create();
            dialog.show();

        }

books_list.xml

  <?xml version="1.0" encoding="utf-8"?>

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:layout_weight="1">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#e6e6e6"
        android:orientation="vertical"
        android:padding="1dp"
        android:scrollbars="vertical"
        android:scrollbarAlwaysDrawVerticalTrack="true">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:orientation="vertical"
            android:padding="1.5dp">

            <ImageView
                android:id="@+id/file"
                android:layout_width="124dp"
                android:layout_height="96dp"
                android:layout_gravity="top|center"
                android:padding="5dp"
                android:src="@drawable/ic_product" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1.5dp"
                android:background="#e6e6e6" />

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TextView
                    android:id="@+id/txtId"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginTop="2dp"
                    android:text="id" />

                <TextView
                    android:id="@+id/txtItem_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:text="Item Name" />
                <TextView
                    android:id="@+id/txtPrice"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@+id/txtItem_name"
                    android:text="0" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
 </ScrollView>

0 个答案:

没有答案