|
|
|
Android : ค่าจาก ArrayList ไม่เข้าไปใน Listview รบกวนช่วยแนะนำผมที |
|
|
|
|
|
|
|
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
|
|
|
|
|
Date :
2013-06-16 18:09:34 |
By :
littlemonkeyz |
View :
1047 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณจะต้อง Debug ดูแล้วครับ ว่ามันมีค่าพวกใน JSON หรือเปล่าครับ
Android and JSON and XML
|
|
|
|
|
Date :
2013-06-16 18:24:40 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ >>>>>> Log.d(TAG,Province_name); ดูแล้ว ค่ามานะครับ
|
|
|
|
|
Date :
2013-06-16 19:38:53 |
By :
littlemonkeyz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง Debug ตัวแปร MyArrList.count มีค่าหรือเปล่าครับ
|
|
|
|
|
Date :
2013-06-17 06:21:07 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|