Reputation: 41
I have an EditText
which InputType is Numeric, and a TextView
. What I want to realize is, when the user inserts some integer value
in the EditText
, make the "Done" button on the Numeric keyboard store the inserted value and display it in the TextView
. How can I realize that? Thanks!!!
Upvotes: 2
Views: 2535
Reputation: 5707
I think you are new to Android. Don't worry just use in xml
<EditText
android:id="@+id/et_ip"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Numeric" />
In Activity
EditText iput= (EditText) findViewById(R.id.et_ip);
TextView oput = (TextView)findViewById(R.id.tv_op);
Button done = (Button)findViewById(R.id.tv_op);
//and onbuttonclick
done.setOnClickListener(new View.OnClickListener() {
String result = iput.getText().toString().trim();
//result have the value in edittext in string
oput.setText(result);
});
Any more doubt ??
Upvotes: 0
Reputation: 2170
First make sure that you have the done ime option set on your EditText
android:imeOptions="actionDone"
Then in the code you add a listener to your EditText
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do something, e.g. set your TextView here via .setText()
return true;
}
return false;
}
});
Upvotes: 6