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 ที่รับ Json Url มาอ่ะครับ คือมัน หน่วง ไม่ไหลลื่นเลย



 

Android - สอบถามเรื่อง การทำให้ Listview ที่รับ Json Url มาอ่ะครับ คือมัน หน่วง ไม่ไหลลื่นเลย

 



Topic : 107364

Guest




นี่เป็นส่วน Getview น่ะครับ พอเลื่อนๆ ละมันกระตุก ไม่ลื่นเลย แก้ไขยังไงดี
Code (Android-Java)
      
    				public View getView(int position, View convertView, ViewGroup parent) {
    					// TODO Auto-generated method stub
    					 
    					  
    				 		 
    					if (convertView == null) {
    						LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    						convertView = inflater.inflate(R.layout.app_custom_list, null); 
    						Holder holder = new Holder();
    						holder.imageView = (ImageView) convertView.findViewById(R.id.ColImgPath);
    						holder.txtPicName = (TextView) convertView.findViewById(R.id.ColTitle);
    						convertView.setTag(holder);
    					}
    					
    					
					
    					HashMap<String, String> entry = MyArr.get(position);
    					if(entry != null) {
    						Holder holder = (Holder)convertView.getTag();
    						// ColImage
    					 holder.imageView.getLayoutParams().height = 130;
    					 holder.imageView.getLayoutParams().width = 130;
    					 holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    		            	 try
    		            	 {
    		            		 holder.imageView.setImageBitmap(loadBitmap(MyArr.get(position).get("store_image")));
    		            	 } catch (Exception e) {
    		            		 // When Error
    		            		 holder.imageView.setImageResource(android.R.drawable.ic_menu_report_image);
    		            	 }
    						
    						
    						// ColPicname
    						
    		            	holder.txtPicName.setPadding(50, 0, 0, 0);
    						holder.txtPicName.setText("ชื่อร้าน : " + MyArr.get(position).get("store_name"));

    					}
		 
    					return convertView;  						
    				}
    		    } 




Tag : Mobile







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-03-31 08:40:07 By : odinamilk View : 1231 Reply : 1
 

 

No. 1



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



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


  • LayoutInflater น่าจะประกาศเป็น member แล้วใช้วิธี ประกาศ Constructor รับ context กับ data ไม่รู้ว่าเป็น array, ArrayList หรือ HashMap แทนที่จะสร้างใหม่ทุกครั้งที่ getView

  • ส่วน ImageView ตั้งค่า width, height scaleType ใน xml ไปเลยไม่ดีกว่าหรอครับ

  • แล้วก็ส่วนฟังค์ชั่น loadBitmap น่าจะมีผลอยู่เหมือนกัน ไม่ทราบว่าใช้วิธีไหนอะครับ ลองหาพวก library ที่ cache พวกรูปภาพ หรือว่าเพิ่ม Perfomance ดีกว่าเขียนเองครับ

    เช่นพวก Universal Image Loader, Picasso, Volley หรือ ion (https://github.com/koush/ion)




นี่ตัวอ่ย่างที่แก้ครับ ไม่รู้ว่าดีขึ้นไหม

Code (Android-Java)
public class CustomListView extends BaseAdapter {
    
    LayoutInflater mInflater;
    HashMap<K, V> myArr;
    
    public CustomListView(Context context, HashMap<K, V> MyArr) {
        mInflater = LayoutInflater.from(context);
        this.myArr = myArr;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder = new Holder();

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.app_custom_list, null);
            holder = new Holder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.ColImgPath);
            holder.txtPicName = (TextView) convertView.findViewById(R.id.ColTitle);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        HashMap<String, String> entry = MyArr.get(position);

        try  {
            holder.imageView.setImageBitmap
                    (loadBitmap(MyArr.get(position).get("store_image")));
        } catch (Exception e) {
            // When Error
            holder.imageView.setImageResource(android.R.drawable.ic_menu_report_image);
        }

        // ColPicname
        holder.txtPicName.setPadding(50, 0, 0, 0);
        holder.txtPicName.setText("ชื่อร้าน : " + MyArr.get(position).get("store_name"));


        return convertView;
    }
    
}









ประวัติการแก้ไข
2014-03-31 13:10:47
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-31 13:09:20 By : devahoy
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android - สอบถามเรื่อง การทำให้ Listview ที่รับ Json Url มาอ่ะครับ คือมัน หน่วง ไม่ไหลลื่นเลย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 05
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 อัตราราคา คลิกที่นี่