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 : ค่าจาก ArrayList ไม่เข้าไปใน Listview รบกวนช่วยแนะนำผมที



 

Android : ค่าจาก ArrayList ไม่เข้าไปใน Listview รบกวนช่วยแนะนำผมที

 



Topic : 096620



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



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




layout_select_province_dialog แสดงค่า
Code (XML)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".DialogSelectProvinceActivity" >

    <Button
        android:id="@+id/btn_submit_province"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="@string/label_submit" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@+id/btn_submit_province" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <ListView
                android:id="@+id/listView_province1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </ListView>

        </LinearLayout>
    </ScrollView>

</RelativeLayout>


row_layout_select_province
Code (XML)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView_province_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000" />

        <TextView
            android:id="@+id/textView_province_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000" />

    </LinearLayout>

</LinearLayout>




Code (Android-Java)
package com.royle.project_end;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class DialogSelectProvinceActivity extends Activity {
	
	private final String TAG = "internet";
	private ListView listview_province;
	private MyHttpPost poster;
	Context context;
	ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
	     HashMap<String, String> map;
	
	     
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_select_province_dialog);
		
		 
		context = this;
		
		final String id = "aaa";
		
		poster = new MyHttpPost("http://192.168.1.3/test_projectEnd/province.php?when="+System.currentTimeMillis(),context);
		
		ArrayList<NameValuePair> data = new ArrayList<NameValuePair>();
		data.add(new BasicNameValuePair("id",id));
		
		poster.doPost(data, new Handler( ){
			
			public void handleMessage(android.os.Message msg){
				switch(msg.what){
				case MyHttpPost.HTTP_POST_ERROR:
				//respone_username.setText((String)msg.obj);
				break;
				case MyHttpPost.HTTP_POST_OK:
					String response = (String)msg.obj;
					//Toast.makeText(context, response, Toast.LENGTH_LONG).show();
					
					try {
						JSONArray object = new JSONArray(response);
						
						
						
						
						for(int i = 0; i < object.length(); i++){
					              JSONObject c = object.getJSONObject(i);
					              
					  			String Province_id = c.getString("PROVINCE_ID");
					  			String Province_name = c.getString("PROVINCE_NAME");
					  			//Toast.makeText(context, province_id + ":"+ province_name, Toast.LENGTH_LONG).show();
					  			
					              map = new HashMap<String, String>();
					              map.put("province_id", Province_id);
					              map.put("province_name", Province_name);
					              MyArrList.add(map);
					              Log.d(TAG,Province_name);
					           
						}
												
					} catch (JSONException e) {
						Toast.makeText(context, "Unable to convert to Json", Toast.LENGTH_SHORT).show();
						e.printStackTrace();
					}
					
				}
			}
			
		});	
		 
			 			listview_province = (ListView) findViewById(R.id.listView_province1);
						ListAdapter adapter = new SimpleAdapter(this, MyArrList, R.layout.row_layout_select_province, 
								new String[]{"province_id","province_name"},
								new int[]{R.id.textView_province_id,R.id.textView_province_name} );
						listview_province.setAdapter(adapter);	
		
			
						
		
		

	}
}




Tag : Mobile, MySQL, Android, JAVA, Mobile









ประวัติการแก้ไข
2013-06-16 18:11:05
2013-06-16 18:17:34
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-06-16 18:09:34 By : littlemonkeyz View : 968 Reply : 3
 

 

No. 1



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

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

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

คุณจะต้อง Debug ดูแล้วครับ ว่ามันมีค่าพวกใน JSON หรือเปล่าครับ

Android and JSON and XML







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-06-16 18:24:40 By : mr.win
 


 

No. 2



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



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


ใช้ >>>>>> Log.d(TAG,Province_name); ดูแล้ว ค่ามานะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-06-16 19:38:53 By : littlemonkeyz
 

 

No. 3



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

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

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

ลอง Debug ตัวแปร MyArrList.count มีค่าหรือเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-06-17 06:21:07 By : mr.win
 

   

ค้นหาข้อมูล


   
 

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