Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone


Android EditText or Textbox in ListView

Android EditText or Textbox in ListView ตัวอย่างการเขียน Android เพื่ออ้างถึงและอ่านข้อมูลจาก EditText หรือ Textbox ที่อยู่ใน ListView ซึ่ง EditText เหล่านี้จะแสดงแสดงผลตามจำนวนของรายการข้อมูล และเราจะเขียนคำสั่งเพื่ออ้างถึงรายการแต่ล่ะรายการที่ได้ Input เข้าไป

Android EditText or Textbox in ListView


แสดง EditText หรือ Textbox ใน Items ของ ListView ซึ่งจะเห็นว่ามีหลายรายการ ขึ้นอยู่กับจำนวนแถวของข้อมูล

Example

โครงสร้างของไฟล์ประกอบด้วย 3 ไฟล์คือ MainActivity.java, activity_main.xml และ activity_column.xml

Android EditText or Textbox in ListView

activity_main.xml
01.<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
02.    android:id="@+id/tableLayout1"
03.    android:layout_width="fill_parent"
04.    android:layout_height="fill_parent">
05.  
06.    <TableRow
07.      android:layout_width="wrap_content"
08.      android:layout_height="wrap_content" >
09.      
10.     <TextView
11.        android:id="@+id/textView1"
12.        android:layout_width="wrap_content"
13.        android:layout_height="wrap_content"
14.        android:gravity="center"
15.        android:text="ListView and EditText/TextBox : "
16.        android:layout_span="1"
17.        android:textAppearance="?android:attr/textAppearanceMedium" />
18.             
19.    </TableRow>
20. 
21. 
22.    <View
23.        android:layout_height="1dip"
24.        android:background="#CCCCCC" />
25.     
26.     
27.  <LinearLayout
28.        android:orientation="horizontal"
29.        android:layout_width="fill_parent"
30.        android:layout_height="wrap_content"
31.        android:layout_weight="0.1">  
32.      
33.     <ListView
34.         android:id="@+id/listView1"
35.         android:layout_width="match_parent"
36.         android:layout_height="wrap_content">
37.     </ListView>
38.             
39.    </LinearLayout>
40.     
41.  <RelativeLayout
42.        android:layout_gravity="center_vertical|center_horizontal"
43.        android:layout_width="fill_parent"
44.        android:layout_height="wrap_content">
45. 
46.     <Button
47.         android:id="@+id/btnGetItem"
48.         android:layout_width="wrap_content"
49.         android:layout_height="wrap_content"
50.         android:layout_alignParentTop="true"
51.         android:layout_centerHorizontal="true"
52.         android:text="Get Input Item" />
53.      
54.    </RelativeLayout>
55.     
56.    <View
57.        android:layout_height="1dip"
58.        android:background="#CCCCCC" />
59.           
60.    <LinearLayout
61.      android:id="@+id/LinearLayout1"
62.      android:layout_width="wrap_content"
63.      android:layout_height="wrap_content"
64.      android:padding="5dip" >
65. 
66.        <TextView
67.            android:id="@+id/textView2"
68.            android:layout_width="wrap_content"
69.            android:layout_height="wrap_content"
70.            android:text="By.. ThaiCreate.Com" />
71. 
72.    </LinearLayout>
73.     
74.</TableLayout>



Android EditText or Textbox in ListView

activity_column.xml
01.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
02.    android:id="@+id/linearLayout1"
03.    android:layout_width="fill_parent"
04.    android:layout_height="fill_parent" >
05. 
06.    <TextView
07.    android:id="@+id/ColID"
08.        android:layout_width="0dp"
09.        android:layout_height="wrap_content"
10.        android:layout_weight="1"
11.        android:gravity="center"
12.        android:text="ID"/>
13. 
14.    <TextView
15.        android:id="@+id/ColCode"
16.        android:layout_width="0dp"
17.        android:layout_height="wrap_content"
18.        android:layout_weight="1"
19.        android:gravity="center"
20.        android:text="Code"/>
21. 
22.    <TextView
23.        android:id="@+id/ColCountry"
24.        android:layout_width="0dp"
25.        android:layout_height="wrap_content"
26.        android:layout_weight="2"
27.        android:text="=" />
28. 
29.    <EditText
30.        android:id="@+id/txtInput"
31.        android:layout_width="wrap_content"
32.        android:layout_height="wrap_content"
33.        android:layout_weight="1"
34.        android:ems="5" />
35. 
36.</LinearLayout>




MainActivity.java
001.package com.myapp;
002. 
003.import java.util.ArrayList;
004.import java.util.HashMap;
005. 
006. 
007.import android.os.Bundle;
008.import android.app.Activity;
009. 
010.import android.content.Context;
011.import android.util.Log;
012.import android.view.LayoutInflater;
013.import android.view.Menu;
014.import android.view.View;
015.import android.view.View.OnClickListener;
016.import android.view.ViewGroup;
017.import android.widget.BaseAdapter;
018.import android.widget.Button;
019.import android.widget.EditText;
020.import android.widget.LinearLayout;
021.import android.widget.ListView;
022.import android.widget.TextView;
023.import android.widget.Toast;
024. 
025.public class MainActivity extends Activity  {
026.     
027.    ArrayList<HashMap<String, String>> MyArrList;
028.     
029.    @Override
030.    public void onCreate(Bundle savedInstanceState) {
031.        super.onCreate(savedInstanceState);
032.        setContentView(R.layout.activity_main);
033.        
034.        // listView1
035.        final ListView lisView1 = (ListView)findViewById(R.id.listView1);
036.         
037.        MyArrList = new ArrayList<HashMap<String, String>>();
038.        HashMap<String, String> map;
039.         
040.        /*** Rows 1 ***/
041.        map = new HashMap<String, String>();
042.        map.put("ID", "1");
043.        map.put("Code", "TH");
044.        MyArrList.add(map);
045.         
046.        /*** Rows 2 ***/
047.        map = new HashMap<String, String>();
048.        map.put("ID", "2");
049.        map.put("Code", "VN");
050.        MyArrList.add(map);
051.         
052.        /*** Rows 3 ***/
053.        map = new HashMap<String, String>();
054.        map.put("ID", "3");
055.        map.put("Code", "ID");
056.        MyArrList.add(map);
057.         
058.        /*** Rows 4 ***/
059.        map = new HashMap<String, String>();
060.        map.put("ID", "4");
061.        map.put("Code", "LA");
062.        MyArrList.add(map);
063.         
064.        /*** Rows 5 ***/
065.        map = new HashMap<String, String>();
066.        map.put("ID", "5");
067.        map.put("Code", "MY");
068.        MyArrList.add(map);    
069.        
070.        lisView1.setAdapter(new CountryAdapter(this));
071.         
072.         
073.        // Get Item Input
074.        Button btnGetItem = (Button) findViewById(R.id.btnGetItem);
075.        btnGetItem.setOnClickListener(new OnClickListener() {
076.            public void onClick(View v) {
077.                int count = lisView1.getAdapter().getCount();
078.                for (int i = 0; i < count; i++) {
079.                    LinearLayout itemLayout = (LinearLayout)lisView1.getChildAt(i); // Find by under LinearLayout
080.                    TextView txtCode = (TextView)itemLayout.findViewById(R.id.ColCode);
081.                    EditText txtInput = (EditText)itemLayout.findViewById(R.id.txtInput);
082.                     
083.                    String Code = txtCode.getText().toString();
084.                    String Country = txtInput.getText().toString();
085.                     
086.                    Log.d(Code, Country);
087.                     
088.                    Toast.makeText(MainActivity.this, Code + " = " + Country ,Toast.LENGTH_LONG).show(); 
089.                
090.            }
091.        });
092.         
093.    }
094.     
095.     
096.    public class CountryAdapter extends BaseAdapter
097.    {
098.        private Context context;
099. 
100.        public CountryAdapter(Context c)
101.        {
102.            //super( c, R.layout.activity_column, R.id.rowTextView, );
103.            // TODO Auto-generated method stub
104.            context = c;
105.        }
106.  
107.        public int getCount() {
108.            // TODO Auto-generated method stub
109.            return MyArrList.size();
110.        }
111.  
112.        public Object getItem(int position) {
113.            // TODO Auto-generated method stub
114.            return position;
115.        }
116.  
117.        public long getItemId(int position) {
118.            // TODO Auto-generated method stub
119.            return position;
120.        }
121.        public View getView(final int position, View convertView, ViewGroup parent) {
122.            // TODO Auto-generated method stub
123.             
124.            LayoutInflater inflater = (LayoutInflater) context
125.                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
126.          
127.            if (convertView == null) {
128.                convertView = inflater.inflate(R.layout.activity_column, null);
129.                 
130.            }
131.             
132.            // ColID
133.            TextView txtID = (TextView) convertView.findViewById(R.id.ColID);
134.            txtID.setText(MyArrList.get(position).get("ID") +".");
135.             
136.            // ColCode
137.            TextView txtCode = (TextView) convertView.findViewById(R.id.ColCode);
138.            txtCode.setText(MyArrList.get(position).get("Code"));
139.             
140.            return convertView;
141.                 
142.        }
143. 
144.    }
145.     
146. 
147.    @Override
148.    public boolean onCreateOptionsMenu(Menu menu) {
149.        getMenuInflater().inflate(R.menu.activity_main, menu);
150.        return true;
151.    }
152.     
153.}




Screenshot

Android EditText or Textbox in ListView

EditText หรือ Textbox ที่อยู่ใน ListView

Android EditText or Textbox in ListView

ทดสอบ Input ข้อมูลลงในแต่ล่ะช่องรายการของ Items

Android EditText or Textbox in ListView

รายการ Item และ Input ที่ได้แสดงบน LogCat



สำหรับ Code และคำอธิบายสามารถศึกษาได้จาก Code ของ Java ซึ่งเป็นรูปแบบการทำงานง่าย ๆ ที่ทำงานคล้าย ๆ กับ Checkbox กับ GridView และ Checkbox กับ ListView

   
Hate it
Don't like it
It's ok
Like it
Love it
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-07-04 20:31:29 / 2017-03-26 22:23:34
  Download : No files
 Sponsored Links / Related

 
Android ListView แบบ Custom Layout แสดงข้อมูล ListView หลายคอลัมบ์ Multiple Column
Rating :

 
Android ListView and ImageView Image / Text in ListView Custom Layout Column
Rating :

 
Android แสดงรูปภาพ ImageView จาก Web URL ของเว็บไซต์ บน ListView
Rating :

 
Android ListView Padding and Pagination
Rating :

 
Android กับ ListView แสดงข้อมูลจาก Database ของ SQLite
Rating :

 
Android ListView and Checkbox
Rating :

 
Android ListView and Buttons inside Create Custom Command in ListView
Rating :

 
Android Populate ListView ImageView get Image Resource from SD Card
Rating :

 
Android Gesture on ListView Detecting Sliding Items (Flip and Swipe)
Rating :

 
Android and Web Server ของ PHP กับ MySQL แสดงบน ListView ในรูปแบบของ JSON
Rating :

 
Android JSON Retrieving Data from URL Web Server (PHP MySQL and JSON)
Rating :

 
Android ProgressDialog When Click Item in ListView for Download file from Server
Rating :

 
Android Multiple Upload Send file to Server and Show Items ProgressBar in ListView
Rating :

 
Android Multiple Download file in ListView and Show Progress unit percentage
Rating :

 
Android AsyncTask update ListView notifyDataSetChanged when Items Load finish
Rating :

 
Android (ListView/GridView) get Result from Web Server and Paging Pagination
Rating :

 
Android Performance of Listview
Rating :


ThaiCreate.Com Forum
Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่