установить изображение из ImageView на диалог - PullRequest
0 голосов
/ 31 января 2019

Я передаю строковый URL-адрес из фрагмента A в B и загружаю его в imageView

if (obj?.signature_image?.url != null) {
            Glide.with(activity)
                .load(obj?.signature_image?.url.toString())
                .into(imgSignature)
        }

. При нажатии imgSinature появляется всплывающее диалоговое окно, и я хочуустановить изображение в диалоге.Как мне добиться?

signDialog = Util().dialogSignature(getActivity())

 imgSignature.setOnClickListener {
            signDialog.show()
            if (obj?.signature_image?.url != null) {
                signDialog.relativeLayout2.addView(obj?.signature_image?.url)
            }
        }

Util

fun dialogSignature(context: Context?):Dialog{

        var dialog = Dialog(context)
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
        dialog.setContentView(R.layout.dialog_signature)
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        return dialog

    }

dialog_signature

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             xmlns:app="http://schemas.android.com/apk/res-auto"
                                             xmlns:tools="http://schemas.android.com/tools"
                                             android:id="@+id/relativeLayout1"
                                             android:layout_width="match_parent"
                                             android:layout_height="230dp"
                                             android:orientation="vertical"
                                             android:background="@android:color/white">

    <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content"
                  android:background="@color/colorPrimaryShadow"
                  android:orientation="horizontal"
                  android:id="@+id/linearLayout1"
                  android:gravity="center"
                  android:layout_marginBottom="2dp" app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintBottom_toTopOf="@+id/relativeLayout2" app:layout_constraintTop_toTopOf="parent"
                  app:layout_constraintStart_toStartOf="parent">

        <TextView
                android:layout_marginLeft="10dp"
                android:layout_weight="0.4"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Place Signature"
                android:textSize="17sp"
                android:layout_gravity="right"/>

        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
                  android:layout_marginRight="10dp"
                  android:id="@+id/doneTxt"
                  android:text="Done"
                  android:textColor="@color/colorDarkBlue"/>

    </LinearLayout>

    <RelativeLayout android:layout_width="0dp" android:layout_height="0dp"
                    android:id="@+id/relativeLayout2"
                    android:background="@color/colorWhite"
                    app:layout_constraintTop_toBottomOf="@+id/linearLayout1" app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintHorizontal_bias="1.0">
    </RelativeLayout>


    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
              android:layout_below="@+id/linearLayout1"
              android:textColor="@color/colorDarkBlue"
              android:text="Clear" app:layout_constraintStart_toStartOf="parent"
              android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
              android:layout_marginEnd="8dp" app:layout_constraintHorizontal_bias="1.0"
              android:layout_marginBottom="16dp" app:layout_constraintBottom_toBottomOf="parent"
              android:id="@+id/clearTxt"/>

</android.support.constraint.ConstraintLayout>

Ошибка в этой строкеsignDialog.relativeLayout2.addView(obj?.signature_image?.url)

Несоответствие типов.Требуется: Просмотр!Найдено: String?

Действительно раздражает ....

Похоже, ваше сообщение в основном кодовое;пожалуйста, добавьте больше деталей.

Ответы [ 2 ]

0 голосов
/ 31 января 2019

Вы должны добавить ImageView в dialog_signautre.xml, а затем передать signature_image?.url во втором параметре и установить его следующим образом

    fun dialogSignature(context: Context?,url:String?):Dialog{

            var dialog = Dialog(context)
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
            dialog.setContentView(R.layout.dialog_signature)
val imgSignature = dialog.findViewById<ImageView>(your_imageview_id)//added this line
Glide.with(activity)
                .load(obj?.signature_image?.url.toString())
                .into(imgSignature) //added this line
           dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
            return dialog

        }
0 голосов
/ 31 января 2019

Вы пытаетесь добавить строку URL в представление, которое является неправильным.Добавьте ImageView внутри вашего relativeLayout2 и используйте Glide для загрузки URL вашего изображения

<RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp"
     android:id="@+id/relativeLayout2"
     android:background="@color/colorWhite"
     app:layout_constraintTop_toBottomOf="@+id/linearLayout1" 
     app:layout_constraintEnd_toEndOf="parent"
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent"
     app:layout_constraintHorizontal_bias="1.0">

    <ImageView
        android:id="@+id/your_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</RelativeLayout>

и в ваш onClick

imgSignature.setOnClickListener {
    ...
    Glide.with(activity)
        .load(obj?.signature_image?.url.toString())
        .into(signDialog.your_image)
}
...