How to pass edittext value to another activity's edittext?

后端 未结 7 2085
闹比i
闹比i 2020-12-16 07:01

My project\'s requirement is : edittext value is first entered by user and that same value will be visible in another activity\'s editext , which should be read only..

相关标签:
7条回答
  • 2020-12-16 07:26

    You can pass it using Intent's putExtra() method. try this way,

    In First Activity,

    Intent intent = new Intent ( FirstAcvity.this, SecondActivity.class ); 
    intent.putExtra ( "TextBox", editText.getText().toString() );
    startActivity(intent); 
    

    Now, in second activity, use following code,

    Intent i = getIntent(); 
    String text = i.getStringExtra ( "TextBox","" ); 
    // Now set this value to EditText 
    secondEditText.setText ( text ); 
    secondEditText.setEnable(false);
    
    0 讨论(0)
  • 2020-12-16 07:32

    Hope this will help full for you.

    This code for second activity where you want to show the Data from First Activity.

     String mUrl = getIntent().getStringExtra("LinkingWord");
     editTextURL.setText(getIntent().getStringExtra("LinkingWord"));
    

    Don't forget to call EditText ID

      EditText editTextURL = findViewById(R.id.edit_url);
    

    Easy Peasy

    HappyCoding

    0 讨论(0)
  • 2020-12-16 07:40

    get the value of edit text by

    String text = edit_text.getText.toString;
    

    then pass it to other activity like

    intent.putExtra("text", text);
    

    In that activity get it onCreate through bundle like

    Bundle extras = getExtra().getIntent();
    String text = extras.getString("text");
    

    now set this value in your edittext like

    edit_text2.setText(text);
    

    modify this code according to you.

    0 讨论(0)
  • 2020-12-16 07:40

    Basically its not a big deal to pass edittext value to textview present in other activity just follow 2steps....

    PROCESS

    1. get two Activities(java classes)

    2. in first Activity take editview

    3. in second Activity take textview

    4. dont forget to create a button and set Onclicklister to it

    5. code the step2 in first activity inside button onclicklisten

    6. now code the step3 in second activity

    7. now run the code

      ((where "name" is indicated as a token to verify so maintain same char in both activities))

    STEP1

    1.Mainactivity.this//(Activity from where you should get the value)

    EditText edittext=(EditText)findViewById(R.id.edittext);
    Intent intent=new Intent(getApplicationContext(),Main2Activity.class);
    intent.putExtra ( "name", ed1.getText().toString() );
    startActivity(intent);
    

    STEP2:

    2.Main2activity//(Activity to where you should get the value)

    Textview textview = (TextView) findViewById(R.id.textview);
    Bundle bb;
    bb=getIntent().getExtras();
    textview.setText(bb.getString("name"));
    
    0 讨论(0)
  • 2020-12-16 07:41

    Based on Lucifer's answer you could use a TextView in the second activity:

    First Activity:

    Intent intent = new Intent ( FirstAcvity.this, SecondActivity.class ); 
    intent.putExtra ( "text", editText.getText().toString() );
    startActivity(intent); 
    

    Second Activity:

    Intent i = getIntent();
    tv.setText(i.getStringExtra("text"); //tv is the TextView
    
    0 讨论(0)
  • 2020-12-16 07:41
    public EditText var_name; 
    
    var_name=(EditText)findViewById(R.id.input_id);
    
    publc void function_name(){
        Intent i=new Intent(this, class_name.class);
        String s=this.edittext_var_name.getString().toString();
        i.putExtra("var_name","s");
        startActivity(i);
        }`
    
    0 讨论(0)
提交回复
热议问题