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 อะคับ มันเออเร่อตรงเก็ตไซอะคับ



 

Android - มีปัญหาเรื่องของ การยัดค่าเข้า ListView อะคับ มันเออเร่อตรงเก็ตไซอะคับ

 



Topic : 106229



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



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




Code (Android-Java)
package com.estimote.examples.demos;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class SearchActivity extends Activity {

	public static final int DIALOG_DOWNLOAD_JSON_PROGRESS = 0;
	private ProgressDialog mProgressDialog;

	ArrayList<HashMap<String, Object>> MyArrList;

	private final String NAMESPACE = "xxxxxx";
	private final String URL = "xxxxxxxx"; // WSDL
																												// URL
	private final String SOAP_ACTION = "xxxxxxx";
	private final String METHOD_NAME = "xxxxxx"; // Method on web

	@SuppressLint("NewApi")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search);

		// Permission StrictMode
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}

		// Download JSON File
		new DownloadJSONFileAsync().execute();

	}

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case DIALOG_DOWNLOAD_JSON_PROGRESS:
			mProgressDialog = new ProgressDialog(this);
			mProgressDialog.setMessage("Downloading.....");
			mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			mProgressDialog.setCancelable(true);
			mProgressDialog.show();
			return mProgressDialog;
		default:
			return null;
		}
	}

	// Show All Content
	public void ShowAllContent() {
		// listView1
		final ListView lstView1 = (ListView) findViewById(R.id.listView1);
		lstView1.setAdapter(new ImageAdapter(SearchActivity.this, MyArrList));

	}

	public class ImageAdapter extends BaseAdapter {
		private Context context;
		private ArrayList<HashMap<String, Object>> MyArr = new ArrayList<HashMap<String, Object>>();
     
		public ImageAdapter(Context c,
				ArrayList<HashMap<String, Object>> myArrList) {
			// TODO Auto-generated method stub
			context = c;
			MyArr = myArrList;
		}

		public int getCount() {
			// TODO Auto-generated method stub
			return MyArr.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(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);
			}

			ImageView imageView = (ImageView) convertView
					.findViewById(R.id.imgShop);
			imageView.getLayoutParams().height = 300;
			imageView.getLayoutParams().width = 300;
			imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
			try {
				imageView.setImageBitmap((Bitmap) (MyArr.get(position)
						.get("image")));
			} catch (Exception e) {
				// When Error
				imageView
						.setImageResource(android.R.drawable.ic_menu_report_image);
			}

			// ColPosition
			TextView txtPosition = (TextView) convertView
					.findViewById(R.id.txtshopname);
			txtPosition.setPadding(10, 0, 0, 0);
			txtPosition.setText(MyArr.get(position).get("shop_name")
					+ System.getProperty("line.separator")
					+ MyArr.get(position).get("shop_detail"));

			// ColPicname
			// TextView txtPicName = (TextView)
			// convertView.findViewById(R.id.txtshopdetail);
			// txtPicName.setPadding(50, 0, 0, 0);
			// txtPicName.setText(MyArr.get(position).get("shop_detail"));

			return convertView;

		}

	}

	// Download JSON in Background
	public class DownloadJSONFileAsync extends AsyncTask<String, Void, Void> {

		protected void onPreExecute() {
			super.onPreExecute();
			showDialog(DIALOG_DOWNLOAD_JSON_PROGRESS);
		}

		@Override
		protected Void doInBackground(String... params) {
			// TODO Auto-generated method stub

			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			request.addProperty("keyword", "");

			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);

			envelope.setOutputSoapObject(request);

			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

			try {

				androidHttpTransport.call(SOAP_ACTION, envelope);
				SoapObject result2 = (SoapObject) envelope.bodyIn;

				Log.d("test", "allservice" + result2.getProperty(0).toString());
				if (result2 != null) {

					final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
					HashMap<String, String> map;
					JSONObject json = new JSONObject(result2.getProperty(0)
							.toString());
					Log.d("test", "obj: " + json);
					JSONArray data2 = json.getJSONArray("shop");
					Log.d("test", "arr: " + data2.length());
					for (int i = 0; i < data2.length(); i++) {
						JSONObject c = data2.getJSONObject(i);
						map = new HashMap<String, String>();
						map.put("image", c.getString("image"));
						map.put("shop_name", c.getString("shop_name"));
						map.put("shop_detail", c.getString("shop_detail"));
						MyArrList.add(map);
					}

					// OnClick

				} else {
					Toast.makeText(getApplicationContext(),
							"Web Service not Response!", Toast.LENGTH_LONG)
							.show();

				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (XmlPullParserException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;

			
		}

		protected void onPostExecute(Void unused) {
			ShowAllContent(); // When Finish Show Content
			dismissDialog(DIALOG_DOWNLOAD_JSON_PROGRESS);
			removeDialog(DIALOG_DOWNLOAD_JSON_PROGRESS);
		}

	}

	/***** Get Image Resource from URL (Start) *****/
	private static final String TAG = "Image";
	private static final int IO_BUFFER_SIZE = 4 * 1024;

	public static Bitmap loadBitmap(String url) {
		Bitmap bitmap = null;
		InputStream in = null;
		BufferedOutputStream out = null;

		try {
			in = new BufferedInputStream(new URL(url).openStream(),
					IO_BUFFER_SIZE);

			final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
			out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
			copy(in, out);
			out.flush();

			final byte[] data = dataStream.toByteArray();
			BitmapFactory.Options options = new BitmapFactory.Options();
			// options.inSampleSize = 1;

			bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,
					options);
		} catch (IOException e) {
			Log.e(TAG, "Could not load Bitmap from: " + url);
		} finally {
			closeStream(in);
			closeStream(out);
		}

		return bitmap;
	}

	private static void closeStream(Closeable stream) {
		if (stream != null) {
			try {
				stream.close();
			} catch (IOException e) {
				android.util.Log.e(TAG, "Could not close stream", e);
			}
		}
	}

	private static void copy(InputStream in, OutputStream out)
			throws IOException {
		byte[] b = new byte[IO_BUFFER_SIZE];
		int read;
		while ((read = in.read(b)) != -1) {
			out.write(b, 0, read);
		}
	}
	/***** Get Image Resource from URL (End) *****/

}



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

ดูใน logcat มันบอกว่า ตรงนี้มันมีค่าเป็น null ซึ่ง ตอนโหลดเซอวิส ดาต้าก็ได้ครบ แล้วมีปัญหาตอนจะยัดค่าให้ listview



Tag : Mobile







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-02-24 20:00:08 By : kaisiamza View : 1205 Reply : 1
 

 

No. 1



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

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

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

น่าจะเป็น myArrList.Size() น่ะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-02-25 09:00:13 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android - มีปัญหาเรื่องของ การยัดค่าเข้า 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 00
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 อัตราราคา คลิกที่นี่