【 Android 中文開放式課程 】文字輸入框 Edittext
影片教學
佈局畫面
package com.calvinhuo.demoedittext;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private EditText et_Name;
private TextView tv_Show;
private Button btn_Show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_Name = (EditText) findViewById(R.id.et_Name);
tv_Show = (TextView) findViewById(R.id.tv_Show);
btn_Show = (Button) findViewById(R.id.btn_Show);
btn_Show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tv_Show.setText((et_Name.getText().toString()));
}
});
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.calvinhuo.demoedittext.MainActivity"
android:gravity="center">
<EditText
android:id="@+id/et_Name"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_Show"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送出"/>
<TextView
android:id="@+id/tv_Show"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="50dp"/>
</LinearLayout>
執行結果畫面
HKT 線上教室 每週六日 更新影片
▶ YouTube 頻道
https://goo.gl/3f2pJi
▶ KT 線上教室 臉書粉絲團
https://goo.gl/27H9Li
▶ 贊助我們
https://goo.gl/FiKXAu
▶ YouTube 頻道
https://goo.gl/3f2pJi
▶ KT 線上教室 臉書粉絲團
https://goo.gl/27H9Li
▶ 贊助我們
https://goo.gl/FiKXAu
參考資料