如何在java文件中获取XML字符串?
所以,现在我的XML文件中有一个文本元素,它要求用户输入,我如何将这个用户输入输入到我的java文件中,这样我就可以将它作为一个数字使用?这是到目前为止我的XML如何在java文件中获取XML字符串?,java,android,xml,Java,Android,Xml,所以,现在我的XML文件中有一个文本元素,它要求用户输入,我如何将这个用户输入输入到我的java文件中,这样我就可以将它作为一个数字使用?这是到目前为止我的XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/too
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="@+id/uitgaven"
android:layout_weight="1"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:hint="@string/uitgaven"
/>
<EditText android:id="@+id/inkomsten"
android:layout_weight="1"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:hint="@string/inkomsten"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
/>
</LinearLayout>
我的java目前基本上是空的,因为我现在对它不太了解。首先,您必须使用
mEditText=(EditText)findViewById(R.id.uitgaven)
或
mEditText=(EditText)findViewById(R.id.inkomsten)
无论哪一个你需要文本。然后你需要做的就是得到文本本身。你可以通过
String myText = mEditText.getText().toString();
首先,您必须使用
mEditText=(EditText)findViewById(R.id.uitgaven)
或
mEditText=(EditText)findViewById(R.id.inkomsten)
无论哪一个你需要文本。然后你需要做的就是得到文本本身。你可以通过
String myText = mEditText.getText().toString();
首先使用ID获取EditText视图
EditText editText=(EditText)findViewById(R.id.uitgaven);
EditText editText1=(EditText)findViewById(R.id.inkomsten);
接下来获取视图中指定的值
String value,value1 = null;
value=editText.getText().toString();
value1=editText1.getText().toString();
首先使用ID获取EditText视图
EditText editText=(EditText)findViewById(R.id.uitgaven);
EditText editText1=(EditText)findViewById(R.id.inkomsten);
接下来获取视图中指定的值
String value,value1 = null;
value=editText.getText().toString();
value1=editText1.getText().toString();
说真的,请阅读一篇教程。这将大大简化学习阶段,尤其是在这种非常初级的情况下。
EditText et1=(EditText)findViewById(R.id.uirgaven);et1.getText().toStrting()代码>说真的,请阅读教程。这将大大简化学习阶段,尤其是在这种非常初级的情况下。EditText et1=(EditText)findViewById(R.id.uirgaven);et1.getText().toStrting()代码>