Android/Java การทำ AutoComplete

การทำ Auto Complete ด้วย AutoCompleteTextView สามารถกำหนด resource สำหรับใช้ทำ auto-complete ได้ทั้งใน source code และใน resource file

  1. กำหนด resource สำหรับใช้เป็น auto-complete ใน source code
  2. กำหนด resource สำหรับใช้เป็น auto-complete ใน resource file
Continue reading

Android/Java ดู Activity Lifecycle

ดูเมธอดต่างๆของ Android Activity Lifecycle ด้วยการ log ออกมาดู

MethodDescription
onCreatecalled when activity is first created.
onStartcalled when activity is becoming visible to the user.
onResumecalled when activity will start interacting with the user.
onPausecalled when activity is not visible to the user.
onStopcalled when activity is no longer visible to the user.
onRestartcalled after your activity is stopped, prior to start.
onDestroy called before the activity is destroyed.  

ไฟล์ที่เกี่ยวข้อง

  • MainActivity.java
Continue reading

Android/Java การเปิดเท็กซ์ไฟล์จากในเครื่องด้วย Intent.ACTION_OPEN_DOCUMENT

การเปิดอ่านเท็กซ์ไฟล์จากในเครื่องด้วย Intent.ACTION_OPEN_DOCUMENT

กดปุ่ม เพื่อ browse หาเท็กซ์ไฟล์มาแสดง

ไฟล์ที่เกี่ยวข้อง

  • activity_main.xml
  • MainActivity.java
Continue reading

Android/Java การ share ข้อมูลด้วย Intent.ACTION_SEND

การ share ข้อมูลออกไปให้แอพอื่นด้วย Intent.ACTION_SEND เช่น ส่งไปแอพอีเมล แอพไลน์

ใส่ข้อความที่จะส่งออก แล้วกด Share
เลือกว่าจะ share ให้แอพไหน

ไฟล์ที่เกี่ยวข้อง

  • activity_main.xml
  • MainActivity.java
Continue reading

Android/Java แสดงไดอะล็อกปรับแต่งเอง Custom dialog

แสดงไดอะล็อกด้วย AlertDialog.setView

แสดงไดอะล็อกโดยนำ layout_login.xml มาแสดง
โดย button1 แสดงเฉยๆ แต่รับค่ากลับมาใช้ไม่ได้
แต่ button2 แสดงและรับค่ากลับมาใช้ได้

แสดงด้วย setView

ไฟล์ที่เกี่ยวข้อง

  • activity_main.xml
  • MainActivity.java
  • layout_login.xml
Continue reading

Android/Java แสดงไดอะล็อกตัวเลือกแบบ Single choice

แสดงไดอะล็อกด้วย AlertDialog.setItems และ AlertDialog.setSingleChoiceItems

ไดอะล็อก Single choice แบบที่ 1 (setItems) เมื่อกดเลือกรายการแล้ว ก็เลือกเสร็จเลย
ไดอะล็อก Single choice แบบที่ 2 (setSingleChoiceItems) เมื่อกดเลือกรายการแล้ว ต้องกดปุ่ม OK ถึงจะเลือกเสร็จ

แสดงด้วย setItems
แสดงด้วย setSingleChoiceItems

ไฟล์ที่เกี่ยวข้อง

  • activity_main.xml
  • MainActivity.java
Continue reading