-2

Im new to this so sorry if the answer is really obvious...

so I have an EditText were the user inputs their name:

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:ems="10"
        android:id="@+id/editText"
        android:layout_above="@+id/analogClock"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="49dp"
        android:hint="Enter Your Name"/>

When they fill in the name, i would like to take their name and put it into a variable but im really unsure,

Thanks in advance

Scott Hollas
  • 57
  • 1
  • 2
  • 9

3 Answers3

3

In your Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText et = (EditText) findViewById(R.id.editText);
        String text= et.getEditableText().toString();
}
mpromonet
  • 11,326
  • 43
  • 62
  • 91
dieter_h
  • 2,707
  • 1
  • 13
  • 19
0
String s = (EditText)findViewById(R.id.editText).getText().toString()
user547995
  • 2,036
  • 8
  • 33
  • 62
0
 public class MainActivity extends Activity {
 EditText eText; 

 @Override
 protected void onCreate(Bundle savedInstanceState) { 
      eText = (EditText) findViewById(R.id.edittext);
      String str = eText.getText().toString();  
  } 
  }

I understand you want it? Is that so?

MahmutKarali
  • 339
  • 4
  • 8