我正在尝试在布局底部的图标(屏幕图标)http://i.stack.imgur.com/C8WgN.png
时创建一个Toast弹出窗口我希望输入的信息可以像托运地址一样放入Toast通知中
First Last
街
City State Zip
有没有办法在Toast调用Id的EditText视图时执行此操作?
带布局的.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="2" android:orientation="vertical">
<TableRow>
<TextView
android:text="First Name"
android:padding="3dip" android:layout_column="0"/>
<TextView
android:text="Last Name" android:padding="3dip"/>
</TableRow>
<TableRow>
<EditText
android:layout_height="wrap_content"
android:id="@+id/EditText01"
android:inputType="textPersonName"
android:width="150dip"/>
<EditText android:singleLine="true"
android:inputType="textPersonName"
android:isScrollContainer="false"
android:layout_height="wrap_content"
android:id="@+id/EditText02"
android:lines="1" android:width="150dip"></EditText>
</TableRow>
<View
android:background="#FF909090" android:layout_height="2px"/>
<TableRow>
<TextView
android:text="Street Address"
android:padding="3dip" android:layout_column="0"/>
</TableRow>
<TableLayout>
<TableRow android:layout_width="fill_parent">
<TextView
android:text="Line 1"
android:padding="3dip"
android:layout_column="0"/>
<EditText
android:layout_height="wrap_content"
android:id="@+id/EditText03"
android:inputType="textPostalAddress"
android:width="255dip"/>
</TableRow>
<TableRow android:layout_width="fill_parent">
<TextView
android:text="Line 2"
android:padding="3dip" android:layout_column="0"/>
<EditText
android:layout_height="wrap_content"
android:id="@+id/EditText04"
android:inputType="textPostalAddress"/>
</TableRow>
</TableLayout>
<TableLayout>
<TableRow>
<TextView
android:text="City"
android:padding="3dip"
android:layout_column="0" />
<EditText
android:layout_height="wrap_content"
android:id="@+id/EditText05"
android:inputType="text"
android:layout_width="120px"/>
</TableRow>
<TableLayout>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip"
android:text="@string/state" />
<Spinner
android:layout_height="wrap_content"
android:prompt="@string/state"
android:id="@+id/Spinner01"
android:layout_width="wrap_content"/>
<TextView
android:layout_height="wrap_content"
android:text="Zipcode" />
<EditText
android:layout_height="wrap_content"
android:inputType="phone" android:width="80px"/>
</TableRow>
</TableLayout>
</TableLayout>
<View
android:background="#FF909090" android:layout_height="2px"/>
<TableRow>
<TextView
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Telephone Number"
android:padding="3dip"/>
</TableRow>
<TableLayout>
<TableRow>
<EditText
android:layout_height="wrap_content"
android:inputType="phone"
android:layout_width="120dip" />
<Button android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:background="@drawable/ic_monitor_grey"
android:clickable="true" />
</TableRow>
</TableLayout>
</TableLayout>
</ScrollView>
我的.java文件是
public class Basic extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.basic);
Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.state_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
}
答案 0 :(得分:0)
你需要做一些事情。
对于要从中获取值的每个editText区域,您需要使用以下语法样式定义android:id
从Java中的xml布局中检索您要使用的视图。基于以上所述,您需要在onCreate上添加一些内容,如:
EditText phoneField =(EditText)findViewById(R.id.phone_field)
从EditText对象中检索值
String phoneNumber = phoneField.getText()。toString()
在Toast消息中显示该字段 Toast toDisplay = Toast.makeText(context,phoneNumber) toDisplay.show()
你可以做很多额外的事情,但那将是最小的。