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] อยากรู้วิธีเขียน ExpandableListView+SQLite ว่าเขียนอย่างไร



 

[Android] อยากรู้วิธีเขียน ExpandableListView+SQLite ว่าเขียนอย่างไร

 



Topic : 098582



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



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




คือทราบว่า ExpandableListView เชื่อมกับ SQLite Database ได้ไหมครับ
แล้วมี Code ให้ดูไหมครับ

ขอบคุณล่วงหน้าครับ



Tag : Mobile, Android







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-08-01 20:46:02 By : tonfozil View : 3044 Reply : 9
 

 

No. 1



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

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

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

ดึงแบบ ExpandableListView ได้แล้วหรือยังครับ ถ้าได้แล้ว ไปอ่านบทความ SQLite ได้เลยครับ

Android กับ SQLite Database







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 06:26:57 By : mr.win
 


 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2013-08-02 06:26:57
รายละเอียดของการตอบ ::
ยังใช้งาน ExpandableListView ไม่เป็นเลยครับ อิอิ

แต่ SQLite พอได้แล้ว

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 10:21:27 By : tonfozil
 

 

No. 3



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

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

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

ก่อนหน้านี้เคยพยายามอยู่ครับ แต่ยังไม่ได้ครับ รอไว้ Phase 2 จะตามเก็บพวกนี้ให้หมดครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-02 17:29:17 By : mr.win
 


 

No. 4



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



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


Code (Android-Java)
package com.example.expandablelist_db;

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

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;

public class MainActivity extends Activity {
	
	SQLiteDatabase db;
	DBHelper helper;
	Cursor cursor;
	
	ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		helper = new DBHelper(this);
		db = helper.getWritableDatabase();
		
		
		// get the listview
        expListView = (ExpandableListView) findViewById(R.id.expandableListView1);
 
        // preparing list data
        prepareListData();
 
        listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
 
        // setting list adapter
        expListView.setAdapter(listAdapter);
        
        expListView.setOnChildClickListener(new OnChildClickListener() {
			
			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this,GMapV2.class);
				intent.putExtra("ID", childPosition);
				startActivity(intent);
				return true;
			}
		});
        
		
	}

	private void prepareListData() {
		// TODO Auto-generated method stub
		listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();
 
        // Adding Header
        listDataHeader.add("กระทรวงมหาดไทย");
        listDataHeader.add("สำนักงานตำรวจแห่งชาติ");
        listDataHeader.add("กระทรวงกลาโหม");
        listDataHeader.add("กระทรวงการคลัง");
        listDataHeader.add("กระทรวงการท่องเที่ยวและกีฬา");
        listDataHeader.add("กระทรวงการพัฒนาสังคมและความมั่นคงของมนุษย์");
        listDataHeader.add("กระทรวงเกษตรและสหกรณ์");
        listDataHeader.add("กระทรวงคมนาคม");
        listDataHeader.add("กระทรวงเทคโนโลยีสารสนเทศและการสื่อสาร");
        listDataHeader.add("กระทรวงทรัพยากรธรรมชาติและสิ่งแวดล้อม");
        listDataHeader.add("กระทรวงพาณิชย์");
        listDataHeader.add("กระทรวงพลังงาน");
        listDataHeader.add("กระทรวงยุติธรรม");
        listDataHeader.add("กระทรวงแรงงาน");
        listDataHeader.add("กระทรวงวัฒนธรรม");
        listDataHeader.add("กระทรวงอุตสาหกรรม");
        listDataHeader.add("สำนักงานอัยการสูงสุด");
        listDataHeader.add("สำนักงานศาลยุติธรรม");
        listDataHeader.add("สำนักงานพระพุทธศาสนา");
        listDataHeader.add("หน่วยงานอิสระ");
        listDataHeader.add("โรงเรียนอนุบาล");
        listDataHeader.add("โรงเรียนประถม");
        listDataHeader.add("โรงเรียนมัธยม");
        listDataHeader.add("วิทยาลัยสายอาชีพ");
        listDataHeader.add("โรงเรียนเทศบาล");
        listDataHeader.add("ศูนย์พัฒนาเด็ก");
        listDataHeader.add("มหาวิทยาลัย");
 
        // Adding Child Data        
        //กระทรวงมหาดไทย str1
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงมหาดไทย'", null);
        List<String> str1 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str1.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();    
        }
 
        //สำนักงานตำรวจแห่งชาติ str2
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='สำนักงานตำรวจแห่งชาติ'", null);
        List<String> str2 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str2.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();    
        }
 
        //กระทรวงกลาโหม str3
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงกลาโหม'", null);
        List<String> str3 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str3.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงการคลัง str4
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงการคลัง'", null);
        List<String> str4 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str4.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงการท่องเที่ยวและกีฬา str5
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงการท่องเที่ยวและกีฬา'", null);
        List<String> str5 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str5.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงการพัฒนาสังคมและความมั่นคงของมนุษย์ str6
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงการพัฒนาสังคมและความมั่นคงของมนุษย์'", null);
        List<String> str6 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str6.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงเกษตรและสหกรณ์ str7
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงเกษตรและสหกรณ์'", null);
        List<String> str7 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str7.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงคมนาคม str8
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงคมนาคม'", null);
        List<String> str8 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str8.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงเทคโนโลยีสารสนเทศและการสื่อสาร str9
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงเทคโนโลยีสารสนเทศและการสื่อสาร'", null);
        List<String> str9 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str9.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงทรัพยากรธรรมชาติและสิ่งแวดล้อม
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงทรัพยากรธรรมชาติและสิ่งแวดล้อม'", null);
        List<String> str10 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str10.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงพาณิชย์ str11
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงพาณิชย์'", null);
        List<String> str11 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str11.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงพลังงาน str12
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงพลังงาน'", null);
        List<String> str12 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str12.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงยุติธรรม str13
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงยุติธรรม'", null);
        List<String> str13 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str13.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงแรงงาน str14
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงแรงงาน'", null);
        List<String> str14 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str14.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงวัฒนธรรม str15
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงวัฒนธรรม'", null);
        List<String> str15 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str15.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //กระทรวงอุตสาหกรรม str16
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='กระทรวงอุตสาหกรรม'", null);
        List<String> str16 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str16.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //สำนักงานอัยการสูงสุด str17
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='สำนักงานอัยการสูงสุด'", null);
        List<String> str17 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str17.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //สำนักงานศาลยุติธรรม str18
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='สำนักงานศาลยุติธรรม'", null);
        List<String> str18 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str18.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //สำนักงานพระพุทธศาสนา str19
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='สำนักงานพระพุทธศาสนา'", null);
        List<String> str19 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str19.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //หน่วยงานอิสระ str20
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='หน่วยงานอิสระ'", null);
        List<String> str20 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str20.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //โรงเรียนอนุบาล str21
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='โรงเรียนอนุบาล'", null);
        List<String> str21 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str21.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //โรงเรียนประถม str22
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='โรงเรียนประถม'", null);
        List<String> str22 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str22.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //โรงเรียนมัธยม str23
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='โรงเรียนมัธยม'", null);
        List<String> str23 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str23.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //วิทยาลัยสายอาชีพ str24
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='วิทยาลัยสายอาชีพ'", null);
        List<String> str24 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str24.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //โรงเรียนเทศบาล str25
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='โรงเรียนเทศบาล'", null);
        List<String> str25 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str25.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //ศูนย์พัฒนาเด็ก str26
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='ศูนย์พัฒนาเด็ก'", null);
        List<String> str26 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str26.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
        
        //มหาวิทยาลัย str27
        cursor = db.rawQuery("SELECT * FROM "+DBHelper.TABLE_NAME
				+ " WHERE " + DBHelper.COL_CLASS + "='มหาวิทยาลัย'", null);
        List<String> str27 = new ArrayList<String>();
        cursor.moveToFirst();        
        while ( !cursor.isAfterLast() ){  
        	str27.add(cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME)));
            cursor.moveToNext();
        }
 
        listDataChild.put(listDataHeader.get(0), str1); // Header, Child data
        listDataChild.put(listDataHeader.get(1), str2);
        listDataChild.put(listDataHeader.get(2), str3);
        listDataChild.put(listDataHeader.get(3), str4);
        listDataChild.put(listDataHeader.get(4), str5);
        listDataChild.put(listDataHeader.get(5), str6);
        listDataChild.put(listDataHeader.get(6), str7);
        listDataChild.put(listDataHeader.get(7), str8);
        listDataChild.put(listDataHeader.get(8), str9);
        listDataChild.put(listDataHeader.get(9), str10);
        listDataChild.put(listDataHeader.get(10), str11);
        listDataChild.put(listDataHeader.get(11), str12);
        listDataChild.put(listDataHeader.get(12), str13);
        listDataChild.put(listDataHeader.get(13), str14);
        listDataChild.put(listDataHeader.get(14), str15);
        listDataChild.put(listDataHeader.get(15), str16);
        listDataChild.put(listDataHeader.get(16), str17);
        listDataChild.put(listDataHeader.get(17), str18);
        listDataChild.put(listDataHeader.get(18), str19);
        listDataChild.put(listDataHeader.get(19), str20);
        listDataChild.put(listDataHeader.get(20), str21);
        listDataChild.put(listDataHeader.get(21), str22);
        listDataChild.put(listDataHeader.get(22), str23);
        listDataChild.put(listDataHeader.get(23), str24);
        listDataChild.put(listDataHeader.get(24), str25);
        listDataChild.put(listDataHeader.get(25), str26);
        listDataChild.put(listDataHeader.get(26), str27);
		
	}
	
	public void onPause() {  
        super.onPause();  
        helper.close();  
        db.close();   
    }  

}


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-23 16:09:45 By : tonfozil
 


 

No. 5



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



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


Code (Android-Java)
package com.example.expandablelist_db;

import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;

public class GMapV2 extends FragmentActivity {
	Cursor cursor;
	SQLiteDatabase db;
	DBHelper helper;
	GoogleMap map;
	
	LatLng fromMarkerPosition = new LatLng(0,0);
	LatLng toMarkerPosition = new LatLng(0,0);

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_map);
		
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}
		map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
		map.setMyLocationEnabled(true);
		
		helper = new DBHelper(this);
		db = helper.getWritableDatabase();	
		
		final int ID = getIntent().getIntExtra("ID", -1) +1;
		Log.i("Check", String.valueOf(ID));
		
		cursor = db.rawQuery("SELECT * FROM tbOfficial WHERE "+ 
					DBHelper.COL_ID + " ='" + ID + "'", null);
		cursor.moveToFirst();		
		double lat_db = cursor.getDouble(cursor.getColumnIndex(DBHelper.COL_LAT));
		double lng_db = cursor.getDouble(cursor.getColumnIndex(DBHelper.COL_LNG));
		String M_Name = cursor.getString(cursor.getColumnIndex(DBHelper.COL_NAME));
		LatLng toPosition = new LatLng(lat_db, lng_db);
		map.addMarker(new MarkerOptions().position(toPosition).title(M_Name));
		map.animateCamera(CameraUpdateFactory.newLatLngZoom(toPosition, 16));
		
		map.setOnMapClickListener(new OnMapClickListener() {
			public void onMapClick(LatLng arg0) {
				final LatLng coordinate = arg0;
				AlertDialog.Builder builder = new AlertDialog.Builder(GMapV2.this);
				builder.setTitle("Getdirection")
				.setItems(new String[]{ "ต้นทาง (A)", "ปลายทาง (B)" }, new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int position) {
						if(position == 0) 
							fromMarkerPosition = coordinate;
						else if(position == 1)
							toMarkerPosition = coordinate;	
						DrowingformMap();
					}
				});				
				builder.show();
			}
		});		
		DrowingformMap();
	}
	
	public void DrowingformMap() {
		map.addMarker(new MarkerOptions().position(fromMarkerPosition)
		.icon(BitmapDescriptorFactory.fromAsset("A.png"))		
		.title("A"));
		
		map.addMarker(new MarkerOptions().position(toMarkerPosition)
		.icon(BitmapDescriptorFactory.fromAsset("B.png"))		
		.title("B"));
		ArrayList<LatLng> directionPoint = getDirections(fromMarkerPosition, toMarkerPosition);
		
PolylineOptions rectLine = new PolylineOptions().width(4).color(Color.RED);
		
		for(int i = 0 ; i < directionPoint.size() ; i++) {			
			rectLine.add(directionPoint.get(i));
		}
		map.addPolyline(rectLine);
	}	
	
	public static ArrayList<LatLng> getDirections(LatLng latlng1, LatLng latlng2) {
        String url = "http://maps.googleapis.com/maps/api/directions/xml?" 
        		+ "origin=" + latlng1.latitude + "," + latlng1.longitude  
        		+ "&destination=" + latlng2.latitude + "," + latlng2.longitude 
        		+ "&sensor=false&units=metric&mode=driving";
        String tag[] = { "step" };
        
        ArrayList<LatLng> listGeopoints = new ArrayList<LatLng>();
        HttpResponse response = null;
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost(url);
            response = httpClient.execute(httpPost, localContext);
            InputStream in = response.getEntity().getContent();
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(in);
            if (doc != null) {
                NodeList nl1, nl2, nl3;
                nl1 = doc.getElementsByTagName(tag[0]);
                if (nl1.getLength() > 0) {
                    for (int i = 0; i < nl1.getLength(); i++) {
                        Node node1 = nl1.item(i);
                        nl2 = node1.getChildNodes();

                        Node locationNode = nl2.item(getNodeIndex(nl2, "start_location"));
                        nl3 = locationNode.getChildNodes();
                        Node latNode = nl3.item(getNodeIndex(nl3, "lat"));
                        double lat = Double.parseDouble(latNode.getTextContent());
                        Node lngNode = nl3.item(getNodeIndex(nl3, "lng"));
                        double lng = Double.parseDouble(lngNode.getTextContent());
                        listGeopoints.add(new LatLng(lat, lng));

                        locationNode = nl2.item(getNodeIndex(nl2, "polyline"));
                        nl3 = locationNode.getChildNodes();
                        latNode = nl3.item(getNodeIndex(nl3, "points"));
                        ArrayList<LatLng> arr = decodePoly(latNode.getTextContent());
                        for(int j = 0 ; j < arr.size() ; j++) {
                        	listGeopoints.add(new LatLng(arr.get(j).latitude, arr.get(j).longitude));
                        }

                        locationNode = nl2.item(getNodeIndex(nl2, "end_location"));
                        nl3 = locationNode.getChildNodes();
                        latNode = nl3.item(getNodeIndex(nl3, "lat"));
                        lat = Double.parseDouble(latNode.getTextContent());
                        lngNode = nl3.item(getNodeIndex(nl3, "lng"));
                        lng = Double.parseDouble(lngNode.getTextContent());
                        listGeopoints.add(new LatLng(lat, lng));
                    }
                }
                
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listGeopoints;
    }
	
	private static int getNodeIndex(NodeList nl, String nodename) {
		for(int i = 0 ; i < nl.getLength() ; i++) {
			if(nl.item(i).getNodeName().equals(nodename))
				return i;
		}
		return -1;
	}
	
	public static ArrayList<LatLng> decodePoly(String encoded) {
		ArrayList<LatLng> poly = new ArrayList<LatLng>();
		int index = 0, len = encoded.length();
		int lat = 0, lng = 0;
		while (index < len) {
			int b, shift = 0, result = 0;
			do {
				b = encoded.charAt(index++) - 63;
				result |= (b & 0x1f) << shift;
				shift += 5;
			} while (b >= 0x20);
			int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
			lat += dlat;
			shift = 0;
			result = 0;
			do {
				b = encoded.charAt(index++) - 63;
				result |= (b & 0x1f) << shift;
				shift += 5;
			} while (b >= 0x20);
			int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
			lng += dlng;
			
			LatLng position = new LatLng((double) lat / 1E5, (double) lng / 1E5);
			poly.add(position);
		}
		return poly;
	}
	
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-23 16:10:25 By : tonfozil
 


 

No. 6



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



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


คือตอนนี้มีกลุ่มอยู่ทั้ง 27 กลุ่ม
ตอนแสดงหน้าแผนที่ ข้อมูลแสดงแค่กลุ่มแรก

เลือกกลุ่มอื่น ข้อมูลมันก็แสดงที่กลุ่มแรก มันเป็นอะไรหรอครับ ผมไม่เข้าใจเลย ช่วยอธิบาหน่อย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-23 16:15:55 By : tonfozil
 


 

No. 7



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

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

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

ได้แล้วเหรอครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-23 16:16:37 By : mr.win
 


 

No. 8



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



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


ครับ แต่ติดอยู่ที่ เลือกข้อมูลที่อื่น มันจะแสดงแต่ข้อมูลของกลุ่มแรก อะ ไม่รู้แก้ยังไง ช่วยอธิบายหน่อยครับ T^T
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-23 16:19:40 By : tonfozil
 


 

No. 9

Guest


ลองใส่adapter แบบนี้สิครับ ผมก้อก๊อปมาจาก http://tutorial.function.in.th/android/example-expandablelistview แล้วเอามาแปลงๆนิดหน่อยให้รับ head เป็น ArrayList<String> แล้วก้อรับ child เป็น HashMap<String, List<String>>

Code
	protected class MyExpadableAdapter extends BaseExpandableListAdapter
	{
	private ArrayList<String> group = null;
	private HashMap<String, List<String>> children = null;
	public MyExpadableAdapter (ArrayList<String> group, HashMap<String, List<String>> children )
	{
	this.group = group;
	this.children = children;
	}
	public Object getChild ( int groupPosition, int childPosition )
	{
	return this.children.get(group.get(groupPosition)).get(childPosition).toString();
	}
	public long getChildId ( int groupPosition, int childPosition )
	{
	return childPosition;
	}
	public View getChildView ( int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent )
	{
	AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams ( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT );
	TextView textView = new TextView ( context );
	textView.setLayoutParams ( layoutParams );
	textView.setPadding ( 5, 5, 5, 5 );
	textView.setText ( this.children.get(group.get(groupPosition)).get(childPosition).toString());
	return textView;
	}
	public int getChildrenCount ( int groupPosition )
	{
	return this.children.get(group.get(groupPosition)).size();
	}
	public Object getGroup ( int groupPosition )
	{
	return this.group.get(groupPosition);
	}
	public int getGroupCount ( )
	{
	return this.group.size();
	}
	public long getGroupId ( int groupPosition )
	{
	return groupPosition;
	}
	public View getGroupView ( int groupPosition, boolean isExpanded, View convertView, ViewGroup parent )
	{
	AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams ( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT );
	TextView textView = new TextView ( context );
	textView.setLayoutParams ( layoutParams );
	textView.setGravity ( Gravity.CENTER );
	textView.setPadding ( 18, 18, 18, 18 );
	textView.setText ( this.group.get(groupPosition));
	return textView;
	}
	public boolean hasStableIds ( )
	{
	return true;
	}
	public boolean isChildSelectable ( int groupPosition, int childPosition )
	{
	return true;
	}
	}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-02-15 05:03:40 By : theletter
 

   

ค้นหาข้อมูล


   
 

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