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

Registered : 109,027

HOME > Mobile > Mobile Forum > Android Listview มีปัญหาครับ แนะนำทีครับ พอใส่ยาวเกิน error ครับ



 

Android Listview มีปัญหาครับ แนะนำทีครับ พอใส่ยาวเกิน error ครับ

 



Topic : 090090



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



สวัสดีครับ

ผมติดปัญหาครับ ทำตาม https://www.thaicreate.com/mobile/android-listview-checkbox.html เป็นไปได้ดีครับ แต่พอมาเพิ่มข้อมูลลงไป ประมาณ 7-8 id ก็รันได้ปกติ(ถ้ายาวเกินมันจะเป็น scorllview ให้เอง) แต่พอเพิ่มไปเยอะๆ ประมาณรวมกันตั้งแต่ไอดีแรกเป็น 19 ไอดี ผลคือมันบอกว่า error ครับ

ผมอธิบายเข้าใจหรือเปล่า - -"

ท่านไหนพอเข้าใจที่ผมอธิบายรบกวนช่วยด้วยครับ

ขอบคุณครับ



Tag : Android, JAVA, Windows, Mobile







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-01-31 15:09:06 By : kanitinkn View : 1179 Reply : 7
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เข้าใจว่า Object นั้น ๆ ยังไม่ได้ถูกสร้างขึ้นมาน่ะครับ คุณน่าจะต้อง Loop เฉพาะ Rows ที่มันถุกสร้างเท่านั้นครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-31 17:13:11 By : mr.win
 


 

No. 2



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

Code (Android-Java)
package com.Project.project;

import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	ArrayList<HashMap<String, String>> MyArrList;
	ListView lisView1;
	Button btnCheckAll, btnClearAll, btnGetItem;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Values();

		HashMap<String, String> map;

		/*** Rows 1 ***/
		map = new HashMap<String, String>();
		map.put("ID", "1");
		map.put("List", "คณะเกษตรศาสตร์	");
		this.MyArrList.add(map);

		/*** Rows 2 ***/
		map = new HashMap<String, String>();
		map.put("ID", "2");
		map.put("List", "คณะเทคนิคการแพทย์");
		this.MyArrList.add(map);

		/*** Rows 3 ***/
		map = new HashMap<String, String>();
		map.put("ID", "3");
		map.put("List", "คณะทันตแพทย์ศาสตร์");
		this.MyArrList.add(map);

		/*** Rows 4 ***/
		map = new HashMap<String, String>();
		map.put("ID", "4");
		map.put("List", "คณะเทคโนโลยี");
		this.MyArrList.add(map);

		/*** Rows 5 ***/
		map = new HashMap<String, String>();
		map.put("ID", "5");
		map.put("List", "คณะพยาบาลศาสตร์");
		this.MyArrList.add(map);

		/*** Rows 6 ***/
		map = new HashMap<String, String>();
		map.put("ID", "6");
		map.put("List", "คณะเภสัชศาสตร์");
		this.MyArrList.add(map);

		/*** Rows 7 ***/
		map = new HashMap<String, String>();
		map.put("ID", "7");
		map.put("List", "คณะแพทย์ศาสตร์");
		this.MyArrList.add(map);

		/*** Rows 8 ***/
		map = new HashMap<String, String>();
		map.put("ID", "8");
		map.put("List", "คณะมนุษยศาสต์และสังคมศาสตร์");
		this.MyArrList.add(map);

		/*** Rows 9 ***/
		map = new HashMap<String, String>();
		map.put("ID", "9");
		map.put("List", "คณะนิติศาสตร์");
		this.MyArrList.add(map);

		/*** Rows 10 ***/
		map = new HashMap<String, String>();
		map.put("ID", "10");
		map.put("List", "บัณฑิตวิทยาลัย");
		this.MyArrList.add(map);

		/*** Rows 11 ***/
		map = new HashMap<String, String>();
		map.put("ID", "11");
		map.put("List", "คณะวิทยาการจัดการ");
		this.MyArrList.add(map);

		/*** Rows 12 ***/
		map = new HashMap<String, String>();
		map.put("ID", "12");
		map.put("List", "วิทยาลัยบัณฑิตศึกษาการจัดการ");
		this.MyArrList.add(map);

		/*** Rows 13 ***/
		map = new HashMap<String, String>();
		map.put("ID", "13");
		map.put("List", "วิทยาลัยการปกครอง");
		this.MyArrList.add(map);

		// /*** Rows 14 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "14");
		// map.put("List", "วิทยาลัยนานาชาติ");
		// this.MyArrList.add(map);
		
		// /*** Rows 15 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "15");
		// map.put("List", "คณะวิทยาศาสตร์");
		// this.MyArrList.add(map);
		//
		// /*** Rows 16 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "16");
		// map.put("List", "คณะวิศวกรรมศาสตร์");
		// this.MyArrList.add(map);
		//
		// /*** Rows 17 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "17");
		// map.put("List", "คณะศิลปกรรมศาสตร์");
		// this.MyArrList.add(map);
		//
		// /*** Rows 18 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "18");
		// map.put("List", "คณะศึกษาศาสตร์");
		// this.MyArrList.add(map);
		//
		// /*** Rows 19 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "19");
		// map.put("List", "คณะสถาปัตยกรรมศาสตร์");
		// this.MyArrList.add(map);
		//
		// /*** Rows 20 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "20");
		// map.put("List", "คณะสัตวแพทยศาสตร์");
		// this.MyArrList.add(map);
		//
		// /*** Rows 21 ***/
		// map = new HashMap<String, String>();
		// map.put("ID", "21");
		// map.put("List", "คณะสาธารณะสุขศาสตร์");
		// this.MyArrList.add(map);

		this.lisView1.setAdapter(new ListAdapter(this));

		// Check All
		btnCheckAll.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				int count = lisView1.getAdapter().getCount();
				for (int i = 0; i < count; i++) {
					LinearLayout itemLayout = (LinearLayout) lisView1
							.getChildAt(i); // Find by under LinearLayout
					CheckBox checkbox = (CheckBox) itemLayout
							.findViewById(R.id.checkBox_activity_column_1);
					checkbox.setChecked(true);
				}
			}
		});

		// Clear All
		btnClearAll.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				int count = lisView1.getAdapter().getCount();
				for (int i = 0; i < count; i++) {
					LinearLayout itemLayout = (LinearLayout) lisView1
							.getChildAt(i); // Find by under LinearLayout
					CheckBox checkbox = (CheckBox) itemLayout
							.findViewById(R.id.checkBox_activity_column_1);
					checkbox.setChecked(false);
				}
			}
		});

		// Get Item Checked
		btnGetItem.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				int count = lisView1.getAdapter().getCount();
				for (int i = 0; i < count; i++) {
					LinearLayout itemLayout = (LinearLayout) lisView1
							.getChildAt(i); // Find by under LinearLayout
					CheckBox checkbox = (CheckBox) itemLayout
							.findViewById(R.id.checkBox_activity_column_1);
					if (checkbox.isChecked()) {

						// Log.d("Item " + String.valueOf(i), checkbox.getTag()
						// .toString());

						Toast.makeText(MainActivity.this,
								checkbox.getTag().toString(), Toast.LENGTH_LONG)
								.show();
					}
				}
			}
		});

	}

	public class ListAdapter extends BaseAdapter {
		private Context context;

		public ListAdapter(Context c) {
			// super( c, R.layout.activity_column, R.id.rowTextView, );
			// TODO Auto-generated method stub
			context = c;
		}

		public int getCount() {
			// TODO Auto-generated method stub
			return MyArrList.size();
		}

		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		public View getView(final int position, View convertView,
				ViewGroup parent) {
			// TODO Auto-generated method stub

			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			if (convertView == null) {
				convertView = inflater.inflate(R.layout.activity_column, null);

			}

			// code_Id
			TextView txtID = (TextView) convertView
					.findViewById(R.id.textView_activity_column_1);
			txtID.setText(MyArrList.get(position).get("ID") + ".");

			// code_List
			TextView txtList = (TextView) convertView
					.findViewById(R.id.textView_activity_column_2);
			txtList.setText(MyArrList.get(position).get("List"));

			// code_Check
			CheckBox check = (CheckBox) convertView
					.findViewById(R.id.checkBox_activity_column_1);
			check.setTag(MyArrList.get(position).get("List"));

			return convertView;

		}
	}

	private void Values() {
		// TODO Auto-generated method stub
		this.lisView1 = (ListView) findViewById(R.id.listView_activity_main_1);
		this.MyArrList = new ArrayList<HashMap<String, String>>();
		this.btnCheckAll = (Button) findViewById(R.id.btn_CheckAll);
		this.btnClearAll = (Button) findViewById(R.id.btn_ClearAll);
		this.btnGetItem = (Button) findViewById(R.id.btn_Search);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
}




รบกวนช่วยดูหน่อยได้ไหมครับ ว่าควรแก้ตรงไหน ยังไม่เข้าใจเรื่อง HashMap เลยครับ มันคืออะไรยังไม่ทราบเลย ความรู้แรกเริ่มแต่ต้องส่งโปรเจค - -"


ประวัติการแก้ไข
2013-02-05 00:46:28
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-31 20:41:06 By : kanitinkn
 

 

No. 3



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ถ้าผมเอา comment ออก คือ มีลูปเกิน 13 จะ error ทันที

มือใหม่ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-31 20:48:47 By : kanitinkn
 


 

No. 4



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (Android-Java)
				for (int i = 0; i < count; i++) {
					LinearLayout itemLayout = (LinearLayout) lisView1
							.getChildAt(i); // Find by under LinearLayout
					CheckBox checkbox = (CheckBox) itemLayout
							.findViewById(R.id.checkBox_activity_column_1);

					if(checkbox != null)
					{
						checkbox.setChecked(true);
					}
				}


เข้าใจว่ามันหา Chekbox อื่น ๆ ไม่เจอน่ะครับ คือ ListView มันจะแสดงเฉพาะ Checkbox ที่แสดงผลเท่ากับขนาดหน้าจอเท่านั้นครับ ลอง check ก่อนว่ามัน null หรือไม่ (ลองดู Syntax ด้วยครับ)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-01 10:29:15 By : mr.win
 


 

No. 5



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

มีวิธีแก้ไหมครับ ไม่เข้าใจเลย :(
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-02 03:47:42 By : kanitinkn
 


 

No. 6



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ได้เขียนตัวอย่างไปให้แล้วครับ ลองดูดี ๆ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-02-02 07:22:37 By : mr.win
 


 

No. 7

Guest


สวัสดีค่ะ

คือตอนนี้มีปัญหาเดียวกันค่ะ ไม่ทราบว่าแก้ไขได้หรือยังค่ะ รบกวนผู้รู้ขอดูคำตอบด้วยคนนะคะ พยายามหามานานแล้วเหมือนกันค่ะ T^T
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-23 17:31:47 By : อุ้ย
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android Listview มีปัญหาครับ แนะนำทีครับ พอใส่ยาวเกิน error ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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