从现场的EditText的Android的getText [英] Android getText from EditText field
问题描述
我有来自外地的EditText让文本意图将其插入电子邮件作曲家的一个问题。我已经声明在布局文件的EditText场(@ + ID / vnosEmaila):
I have a problem with getting text from EditText field to insert it in Email composer with intent. I've declared EditText field in layout file (@+id/vnosEmaila):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/navodiloEmail"
android:text="@string/navodiloEmail"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/vnosEmaila"
android:layout_below="@id/navodiloEmail"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/navodiloZadeva"
android:text="@string/navodiloZadeva"
android:layout_below="@id/vnosEmaila"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/vnosZadeve"
android:layout_below="@id/navodiloZadeva"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/navodiloBody"
android:text="@string/navodiloBody"
android:layout_below="@id/vnosZadeve"
android:textSize="15dip"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/vnosBody"
android:layout_below="@id/navodiloBody"/>
<Button
android:id="@+id/klicIntentEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sestaviEmail"
android:onClick="sestaviEmail"
android:layout_below="@id/vnosBody"/>
</RelativeLayout>
按钮调用的onClick方法sestaviEmail我已经宣布它:
The button calls onClick method "sestaviEmail" and I have declared it:
public void sestaviEmail (View view){
CharSequence test = getText(R.id.vnosEmaila);
Toast toast = Toast.makeText(EmailGumb.this, test, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
我只是显示它与面包,因为它的速度更快,但每次我尝试从现场的文字,我得到假。我发现所有其他问题了code这方法,而不是在布局声明按钮,也许这就是问题的一部分?
I'm just showing it with Toast because it's faster but everytime I try to get text from field I get "false". All other questions that I've found had code which declared Button in methods and not in layout, maybe this is a part of the problem?
推荐答案
如何从EditText上获得文字
how to get text from EditText
EditText text = (EditText)findViewById(R.id.vnosEmaila);
String value = text.getText().toString();
这篇关于从现场的EditText的Android的getText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!