Mobile Application Developing- Android, iOS, Window Phone สอนเขียนโปรแกรมบนมือถือ ระบบปฏิบัติการต่าง แอนดรอยด์ ไอโอเอส วินโดโฟน สอนเขียนโปรแกรมบนมือถือ
Moderator: mindphp , ผู้ดูแลกระดาน
worachat
PHP Hero Member
โพสต์: 179 ลงทะเบียนเมื่อ: 23/05/2016 9:55 am
โพสต์ที่ยังไม่ได้อ่าน
โดย worachat » 23/05/2016 5:54 pm
ในบทความนี้ จะแสดงให้เห็นถึงตัวอย่างการใช้คำสั่งให้เลือก RadioButton โดย RadioGroup โดยจะแสดงให้เห็นถึงการเขียนคำสั่งภายใน Class Activity, การเขียนคำสั่งภายในไฟล์ XML Layout ดังนี้
การเขียนคำสั่งภายในไฟล์ XML Layout
โค้ด: เลือกทั้งหมด
<RadioGroup
android:id="@+id/MD"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical">
<RadioButton
android:id="@+id/Yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes" />
<RadioButton
android:id="@+id/No"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No" />
</RadioGroup>
layout1.png (44.65 KiB) Viewed 1041 times
การเขียนคำสั่งภายใน Class Activity
โค้ด: เลือกทั้งหมด
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
public class MainActivity extends Activity
{
public void onCreate ( Bundle savedInstanceState )
{
super.onCreate ( savedInstanceState );
this.setContentView ( R.layout.activity_main );
RadioGroup select = ( RadioGroup ) this.findViewById ( R.id.MD );
MD.check ( R.id.No);
}
}
java1.png (32.43 KiB) Viewed 1041 times
สามารถเรียนรู้เพิ่มเติมได้ที่ พัฒนาโปรแกรมบน Android และสร้าง Project
0 ตอบกลับ
5496 แสดง
โพสต์ล่าสุด โดย nuattawoot
06/06/2017 5:12 pm
0 ตอบกลับ
3396 แสดง
โพสต์ล่าสุด โดย Four
09/01/2018 2:47 pm
0 ตอบกลับ
3694 แสดง
โพสต์ล่าสุด โดย prakasit.bank
04/06/2015 4:52 pm
1 ตอบกลับ
6497 แสดง
โพสต์ล่าสุด โดย AorKarn_sitikwan
26/05/2018 10:17 pm
0 ตอบกลับ
3717 แสดง
โพสต์ล่าสุด โดย nuattawoot
17/07/2017 2:50 pm
1 ตอบกลับ
1351 แสดง
โพสต์ล่าสุด โดย fonfonn
19/07/2022 8:46 am
0 ตอบกลับ
1896 แสดง
โพสต์ล่าสุด โดย Four
09/01/2018 1:27 pm
0 ตอบกลับ
3277 แสดง
โพสต์ล่าสุด โดย fonfonn
20/07/2022 5:10 pm
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 56