我使用textview,edittext和按鈕進行了簡單的活動。 我試圖在按鈕按下時在textview中顯示edittext的值。將值設置爲textview時,應用程序崩潰
public void click() {
EditText text1 = (EditText) findViewById(R.id.Text1);
TextView text2 = (TextView) findViewById(R.id.Text2);
text2.setText("text");
};
}
XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/Text1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="click" />
</LinearLayout>
當我按下按鈕的應用程序崩潰
。
謝謝你,先生它的工作 –
不用客氣, – Blackbelt
@Purushotamrawat如果這個答案已經成功地滿足你的需求,請檢查問題聲譽下面的回答標誌(左邊)。 – Bonatti