• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android Button setOnClickListener call function to change text

I have an app with multiple buttons and text lines, I want to change the text depending on the language set in a menu. Ideally I want all the changes within a function to make the code easier, but the code does not work. I am not sure even if the function is been called, how do I change the text within the function when trigged by the button?

MainActivity.kt

Code:
package com.example.sandpit9

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        imageButton1.setOnClickListener{toast(R.)}

        imageButton1.setOnClickListener{
            imageButton1.setImageResource(R.drawable.greenbutton)
            textView1.setText("test 1")

        }

    }

    private fun toast() {

        val text: Any = textView2
        textView2.setText("test 2")


    }

}

MainActivity.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <TextView
            android:text="TextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView1"
            android:layout_marginTop="8dp"
            app:layout_constraintTop_toBottomOf="@+id/imageButton1"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:textSize="34sp"/>
    <ImageButton
            android:layout_width="174dp"
            android:layout_height="154dp"
            app:srcCompat="@drawable/download"
            android:id="@+id/imageButton1"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHorizontal_bias="0.542"
            app:layout_constraintVertical_bias="0.187"/>
    <TextView
            android:text="textvar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textView2"
            android:textSize="34sp" android:layout_marginTop="108dp"
            app:layout_constraintTop_toBottomOf="@+id/imageButton1" android:layout_marginEnd="8dp"
            app:layout_constraintEnd_toEndOf="parent" android:layout_marginRight="8dp" android:layout_marginStart="8dp"
            app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="8dp"
            app:layout_constraintHorizontal_bias="0.535"/>
</android.support.constraint.ConstraintLayout>

Device clone, possible?

Hi guys, i have a problem with unknown devices.

I have 2 same ROOTED devices, so i was trying to change /system/build.prop and i didnt have permission, so I was trying so much things and i got device that wont boot :)

Device is custom tv, very unusual, android board model is ad500a , cant find informations about it on net.

So, when i power on device, it only shows boot image, my pc doesnt see it, adb devices shows nothing.

Is there any way to clone or whatever nand from the same device? I have .ab file from it.

Thank you so much

Does displaying xperia xz2 on a tv via HDMI work after Pie?

Hi all,

Just wondering if USB C to HDMI for mirroring my phone to my TV is working after PIE was released and changed a lot of basic functionality?

I've been googling and can see loads of USBC to HDMI adapters for sale but no info in the form of forum posts or helpful topics/videos which clarify if it still works.

I just wanted to verify if it would still work before splashing the cash, and I've read stories about Pie ruining lots of different functions/aspects of android behaviour

Thanks in advance!

Moneyac - Free Monopoly Game

https://play.google.com/store/apps/details?id=com.ozgames.moneyac


Moneyac is a free business board game.You can play against the Artificial Intelligence or your friends.All this and much more is enabled in Moneyac, the real-estate board game that you will love.
The aim of the game is to become millionaire among the all players and to make as much money and property as you can.
To win, you must play very well and need to be a little lucky. Just Roll the dice and be monopol in the world.
Buy lands, trade properties, win auctions, mortgage properties, pay rent and build houses and hotels,force your opponents to bankruptcy and stay away from jail.

83SD3a7P2RYmujMfcrmXxtF6trX0bbvx-0rWYCNR4HkY4rZMxVXTSV3_q-Z8f5onlg=w1150-h654

99.℅ sure my phone is hack HELP

Okay so I'm pretty sure it is
a few times at exactly 12:00am
My call logged Showed my exs number
As if I dialed her?
I feel like she may have put me on gsuites
Or something to do with voice commands
This is just a odd few things
To give you an idea

If I change my settings they will go back what they were

The Playstore is not united states

WiFi connects\disconnects rapidly

The date/time changes almost every time the battery dies (gos back hours)

Location is sometimes wrg

Every app has odd permissions requesting


FIRST 4 PICS ARE THE GALLERIES PERMISSIONS

Attachments

  • Screenshot_2019-04-09-00-49-33.png
    Screenshot_2019-04-09-00-49-33.png
    113 KB · Views: 247
  • Screenshot_2019-04-09-00-49-29.png
    Screenshot_2019-04-09-00-49-29.png
    115.1 KB · Views: 212
  • Screenshot_2019-04-09-00-49-24.png
    Screenshot_2019-04-09-00-49-24.png
    122.2 KB · Views: 210
  • Screenshot_2019-04-09-00-49-05.png
    Screenshot_2019-04-09-00-49-05.png
    94 KB · Views: 207
  • Screenshot_2019-04-09-00-48-12.png
    Screenshot_2019-04-09-00-48-12.png
    105.9 KB · Views: 236
  • Screenshot_2019-04-09-00-43-20.png
    Screenshot_2019-04-09-00-43-20.png
    78 KB · Views: 220
  • Screenshot_2019-04-09-00-42-26.png
    Screenshot_2019-04-09-00-42-26.png
    54.9 KB · Views: 203

TraficStats vs NetworkStatsManager

I want to calculate data usage in android application for LTE and Wi-Fi data usage. For that my current implementation is using TraficStats API from android. I am not getting accurate data from this. Also let me know which are the other scenarios where TraficStats not giving accurate data. In case if I want to Use NetworkStatsManager, It will asking data usage permission, which need to be enabled by user that I don't want to use. Kindly suggest.

how to prevent a notification

Sorry, I am not sure I am using the right terminology...

When I type my email id on Chrome browser on Windows, my email id comes up along with a list of matching suggestions. Also in the list is some European soccer team. My email id shares some of the same characters as that team's name. Sadly, I accidentally clicked on that team link instead of my email id. That was on Windows.

Now I get notifications for game scores on my Android phone. When I swipe down from the very top of the phone's screen, I see the current notifications. I wish to not get the updates about those soccer games.

Transfer to sd

I just got a new Sandisk 32 gb sd card. I want to transfer as much as I can from phone storage to sd. For instance, I want to move X-plore. In fact, I thought it had a way to move things to sd. I can't find it, though. Would Send Anywhere work? Why has it been removed? Would it be possible to get another version that still has working Send Anywhere?

GamerROM's 4th Anniversary!

With GamerROM Orion on the Nexus 6 i feel great that over a year im back into the scene of developing GamerROM!

I want to hear your options of what matters most in a gaming os and i do want to announce that i am using a new audio engine that will keep those music lovers happy.

Not only im makng this post because im excited to be back , im making this post because of on Apr 12th, 2019 is GamerROM'S 4th Anniversary! For 4 years GamerROM has evolved and is now evolved using new technology that makes it even better!

Share your memories about using gamerrom or your opinions on it to celebrate the anniversary!

Asphalt 9 lags on s10 plus

Hello, I have s10 plus the snapdragon variant and I noticed some games do not run smoothly on it. For instance, asphalt 9 lags a lot with dropped frames . I also noticed I have no option to increase the graphics quality for the game.. it is either performance or default. My s9 plus usee to run it on the high quality settings without problems. Does anyone else have the same problem? Thanks

App to record phone movement/position in real time

Is there an app that could record phone movement maybe using its accelerometer and gyroscope to be able to replicate or record its movement?

Just to make it clear, I don't want to track the phone position relative to the GPS coordinates, I want to track the phone's movement in space so if I make a whipping movement, that would be recorded and maybe played back on a 3d model.

Is there an app like this or is it even possible to achieve having the input from the phone's sensors?

New math

It looks like there's some kind of new math around these days, math I definitely missed in five college math courses.

I was sitting here minding my own business when I became aware of it. This bottle of "Orange Creme" flavored water I'm drinking is sitting on my nightstand. Its back was toward me as I reached for it, and this is where I saw...it...new math!

1554755298034.jpg


See it? The calories?

Anyone know when this new law involving zero came along?

Filter

Back
Top Bottom