Home > Enterprise >  GLIDE How to modificate a .load(url) durring the app session while using a button?
GLIDE How to modificate a .load(url) durring the app session while using a button?

Time:03-11

i hope you are well :) I'm trying to load a .gif from url by a button and be able to modificate the url and save durring the app session. For now i can only run the gif if i've put it between the .load("url") I've set a EditText File so i can try to call the R.id.EditText, also tried with a getString but when i'm in the app and i replace the EditText with an other url it don't recognize it...

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_player)
    imageView = findViewById(R.id.viewgif)
    greenbtn = findViewById(R.id.gogreenralph)
    greenbtn.setOnClickListener{
        Glide.with(this)
            .load("https://i.makeagif.com/media/4-19-2017/V1hRLP.gif")
            .into(imageView)
    }

Also tried :

enter code hereval greenstring: String name = getString(R.string.urlgreen)
    imageView = findViewById(R.id.viewgif)
    greenbtn = findViewById(R.id.gogreenralph)
    greenbtn.setOnClickListener{
        Glide.with(this)
            .load(greenstring)
            .into(imageView)
    }

And :

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_player)
    var greentext = findViewById(R.id.greengif) as EditText
    imageView = findViewById(R.id.viewgif)
    greenbtn = findViewById(R.id.gogreenralph)
    greenbtn.setOnClickListener{
        Glide.with(this)
            .load(greentext)
            .into(imageView)
    }

activity.xml :

<EditText
    android:id="@ id/greengif"
    android:text="@string/urlgreen"
    android:layout_width="180dp"
    android:layout_height="233dp"
    android:layout_marginStart="381dp"
    android:rotation="90"
    android:textColor="@color/black"
    android:textColorHint="@color/black"
    android:textSize="20sp"
    app:layout_constraintStart_toStartOf="parent" />

<Button

    android:id="@ id/gogreenralph"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:background="@drawable/greenralphthesquare"
    android:rotation="90"
    app:layout_constraintBottom_toBottomOf="parent"
    tools:layout_editor_absoluteX="0dp" />

And of course ImageView :

<ImageView
    android:id="@ id/viewgif"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:rotation="90"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

I sincerly hope someone can help me with that i'm a complete beginner and i've really tried my best ):

CodePudding user response:

You should get the content of EditText and pass it to load(), something like below:

var greentext = findViewById(R.id.greengif) as EditText
imageView = findViewById(R.id.viewgif)
greenbtn = findViewById(R.id.gogreenralph)
greenbtn.setOnClickListener{
    Glide.with(this)
        .load(greentext.text.toString())
        .into(imageView)
}
  • Related