我的 xml
<TextView
android:id="@+id/newPlaceLatLable"
android:text="Place Latitude"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_below="@id/newPlaceLable"/>
<EditText
android:id="@+id/newPlaceLat"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_toRightOf="@id/newPlaceLatLable"
android:layout_below="@id/newPlaceLable"
android:inputType="numberDecimal"
/>
<TextView
android:id="@+id/newPlaceLonLable"
android:text="Place Longitude"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_below="@id/newPlaceLatLable"/>
<EditText
android:id="@+id/newPlaceLon"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_toRightOf="@id/newPlaceLonLable"
android:layout_below="@id/newPlaceLatLable"
android:inputType="numberDecimal"
/>
并在代码中
if (et1.getText().toString().matches(""))
Toast.makeText(getApplicationContext(), "Name can't be null", Toast.LENGTH_SHORT).show();
else if (et2.getText().toString().matches(""))
Toast.makeText(getApplicationContext(), "Latitute can't be null", Toast.LENGTH_SHORT).show();
else if (et3.getText().toString().matches(""))
Toast.makeText(getApplicationContext(), "Longitute can't be null", Toast.LENGTH_SHORT).show();
其中 et1、et2 和 et3 是
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change);
et1 = (EditText) findViewById(R.id.newPlaceText);
et2 = (EditText) findViewById(R.id.newPlaceLat);
et3 = (EditText) findViewById(R.id.newPlaceLon);
但是每次我运行应用程序时,它都会吐司“Latitute不能为空”。虽然 et2 里面有文字,但是这里没有显示。请看一下。什么问题