-2

I am a beginner of coding Android. I was designing an app which needs to record users' info. I understand how to get Text from EditText and show as TextView on another activity. I am confused on how to pass putExtra() value into EditText, can anyone give me some suggestion??

First Activity:

......
abc.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
            Intent agreeTerms = new Intent(terms.this, user_info.class);
            agreeTerms.putExtra("Email ID on plan_type", getEmail);
            startActivity(agreeTerms);
    }
}
......

Second Activity (Which receive putExtra() value from First Activity):

public class user_info extends AppCompatActivity {
    EditText getEmail;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_info);
        getEmail = (EditText)findViewById(R.id.txtEmail);

        if (savedInstanceState == null) {
            Bundle extras = getIntent().getExtras();
            if(extras == null) {
                getEmail = null;
            } else {
                getEmail = extras.getString("Email ID on plan_type");
                getEmail.setText(getEmailFromID, TextView.BufferType.EDITABLE);
            }
        }
    }
}

Thanks for everyone to see and answer my problem.

Chris.C
  • 297
  • 3
  • 17
  • 2
    You put `getEmail` as a value for your `extra` - what type is this? Or are you trying to get the value of the `EditText` where the user would have entered her email? Also consider making the key to be just "email" - I don't see why you'd use a sentence as a key. – ishmaelMakitla Aug 30 '16 at 09:53
  • @ishmaelMakitla , good suggestion. Developer should name the key with clear, concise meaning. By the way, what is the meaning of variable "getEmailFromID". – Long Ranger Aug 30 '16 at 09:58
  • The code snippet included the compile time error. I wonder why every reply can answer without looking it in detail. – Long Ranger Aug 30 '16 at 10:03
  • 2
    Possible duplicate of [How do I get extra data from intent on Android?](http://stackoverflow.com/questions/4233873/how-do-i-get-extra-data-from-intent-on-android) – Md Imran Choudhury Aug 30 '16 at 10:32
  • @ishmaelMakitla It's because I need to intent that value from previous activities which more than 1 and for log ( I delete the Log.e() here). – Chris.C Aug 31 '16 at 01:02
  • I must feel sorry for everyone. I am careless for proof-reading and debug the application who coded by ex-colleague. The EditText's color changes to #FFFFFF (I don't know why or some support library conflicts with it.). So I highlight on it, it has value without any changes of the code. – Chris.C Aug 31 '16 at 01:26
  • @LongRanger Which activity/ies have compile time error? I am willing to understand. Cheers. – Chris.C Aug 31 '16 at 01:33
  • If you just put the activity code in a new class, you will see the "getEmailFromID" cannot be resolve as symbol, getEmail variable with incompatible type in extras.getString("Email ID on plan_type") statement – Long Ranger Aug 31 '16 at 01:35
  • @LongRanger Thanks for your answer, I will correct it. – Chris.C Aug 31 '16 at 01:53

4 Answers4

1
  Intent intent=getIntent();
  if(intent!=null){
      Bundle bundle=intent.getExtras();
      if(bundle!=null){
         String value = bundle.getString("Email ID on plan_type");
         if(value != null)
          { 
            getEmail.setText(value);

          }
      }
  }
Jinesh Francis
  • 3,377
  • 3
  • 22
  • 37
Avinash Mishra
  • 281
  • 3
  • 21
0
getEmail.setText(getIntent().getStringExtra("Email ID on plan_type"));
Soham
  • 4,397
  • 11
  • 43
  • 71
user2582324
  • 1,220
  • 1
  • 9
  • 10
0

In First activity:

abc.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
            Intent agreeTerms = new Intent(terms.this, user_info.class);
            agreeTerms.putExtra("Email ID on plan_type",editText.getText().toString());
            startActivity(agreeTerms);
    }
}

In SecondActivity:

public class user_info extends AppCompatActivity {
    EditText getEmail;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_info);
        getEmail = (EditText)findViewById(R.id.txtEmail);

        if (savedInstanceState == null) {
                String getEmail =getIntent().getStringExtra("Email ID on plan_type");
                getEmail.setText(get_Email);

        }
    }
}
sneha desai
  • 886
  • 1
  • 11
  • 19
0

I must feel sorry for everyone. I am careless for proof-reading and debug the application who coded by ex-colleague. The EditText's color changes to #FFFFFF (I don't know why or some support library conflicts with it.). So I highlight on it, it has value without any changes of the code.

I am apologize to members who are wasting time to read or answer my dumb question.

Chris.C
  • 297
  • 3
  • 17