<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="18dp" android:text="Please input Your Name ?" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:ems="10" android:inputType="textPersonName" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_marginTop="15dp" android:text="Button" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button1" android:layout_centerHorizontal="true" android:layout_marginTop="36dp" android:text="TextView" /> </RelativeLayout>
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.TextView; import android.widget.Button; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // button final Button btn1 = (Button) findViewById(R.id.button1); // textView final TextView textV2 = (TextView)findViewById(R.id.textView2); // Input Text final TextView editT1 = (TextView)findViewById(R.id.editText1); // Perform action on click btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String strTxt = editT1.getText().toString(); textV2.setText("Sawatdee khun : " + strTxt); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="18dp" android:text="Please input Your Name ?" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:ems="10" android:inputType="textPersonName" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_marginTop="15dp" android:text="Button" /> </RelativeLayout>
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.TextView; import android.widget.Button; import android.app.AlertDialog; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final AlertDialog.Builder adb = new AlertDialog.Builder(this); // button final Button btn1 = (Button) findViewById(R.id.button1); // Input Text final TextView editT1 = (TextView)findViewById(R.id.editText1); // Perform action on click btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog ad = adb.create(); String strTxt = editT1.getText().toString(); //ad.setMessage(editTxt.getText()); ad.setMessage("Sawatdee khun : " + strTxt); ad.show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
package com.myapp; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.TextView; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // button final Button btn1 = (Button) findViewById(R.id.button1); // Input Text final TextView editT1 = (TextView)findViewById(R.id.editText1); // Perform action on click btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String strTxt = editT1.getText().toString(); Toast.makeText(MainActivity.this, "Sawatdee khun : " + strTxt, Toast.LENGTH_LONG).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท