getText and setText function not working in android studio

Rathore Brothers

i tried to make my first converter in android studio with java but 2 functions setText and getText are not working

package com.example.unitconvertor;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity<editTextTextPersonName> extends AppCompatActivity {
    private Button button;
    private editTextTextPersonName editTextTextPersonName;
    private View editText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = findViewById(R.id.button);

        

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "value saved", Toast.LENGTH_SHORT).show();
                String s = editText.getText().toString();
                int inch = Integer.parseInt(s);
                double cm = 2.54 * inch;
                editText.setText( "the value is" + cm);
            }
        });
    }
}

i hope that i am clear thankyou

Sandesh KhutalSaheb

Try this-

public class MainActivity extends AppCompatActivity  {
    private Button button;
    private EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
        button = findViewById(R.id.button);
        editText = findViewById(R.id.your_id);//ADD YOUR EDIT TEXT ID HERE


        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this, "value saved", Toast.LENGTH_SHORT).show();
                String s = editText.getText().toString();
                int inch = Integer.parseInt(s);
                double cm = 2.54 * inch;
                editText.setText( "the value is" + cm);
            }
        });
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

setText on ID not working in android studio

Kotlin Android Studio, getText() not working as I want

.setText(" text ") is not working properly in android studio

SetText not working in Android Studio using Java

Android Java: Diaglog setText & getText issue

Wait Function not working Android Studio

onClick function not working in android studio

not getting getText() option in android studio

Android Studio gettext not updating on click

How to use gettext and settext

wait() function not working in thread in android studio

SQLLITE/ Android Studio Update Function Not Working

Android Studio - Cannot resolve method 'setText(double)'

TextView setText from another class Android Studio

How to setText to a PopUp Window In Android Studio?

Trying to permanently setText using java Android Studio

Function "Format code (Ctrl + Alt +l)" in Android studio, not working properly

Android Studio: scrollTo in Horizontal function isn't working

JavaFX getText(), setText(), toString() give Null Pointers

Android: Why is subsequent code preventing .setText() for TextView from working

Method getText() must be called from the UI Thread (Android Studio)

Why can't I resolve symbol "setText" in Android Studio?

Android Studio Error: String literal in setText cannot be translated

why doesn't setText of TextView work in android studio in kotlin?

Android Studio with Firebase Not Working

Android studio @strings not working

Android Studio assert not working

Android studio logcat not working

Android Studio emulator is not working

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive