全国城市检索

时间:2018-01-17 09:30:25
【文件属性】:

文件名称:全国城市检索

文件大小:135KB

文件格式:RAR

更新时间:2018-01-17 09:30:25

city

package cc.lifelink.cn; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; public class City_cnActivity extends Activity { private DBManager dbm; private SQLiteDatabase db; private Spinner provinceSpinner; private Spinner citySpinner=null; private Spinner districtSpinner=null; private String province=null; private String city=null; private String district=null; /*------------------*/ // private TextView provinceView; // private TextView cityView; // private TextView districtView; // private ImageView provinceImageView; // private ImageView cityImageView; // private ImageView districtImageView; // // private PopupWindow mPopupWindow; // private ListView provinceListView /*------------------*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); provinceSpinner=(Spinner)findViewById(R.id.spinner1); citySpinner=(Spinner)findViewById(R.id.spinner2); districtSpinner=(Spinner)findViewById(R.id.spinner3); provinceSpinner.setPrompt("鐪?鐩磋緰甯?); citySpinner.setPrompt("鍩庡競"); districtSpinner.setPrompt("鍦板尯"); provinceSpinner.setOnItemSelectedListener(new ProvinceOnSelectedListener()); districtSpinner.setOnItemSelectedListener(new DistrictOnSelectedListener()); citySpinner.setOnItemSelectedListener(new CityOnSelectedListener()); dbm = new DBManager(this); provinceSpinner(); // initUI(); } // private void initUI(){ // provinceView = (TextView) findViewById(R.id.tv_province); // cityView = (TextView) findViewById(R.id.tv_city); // districtView = (TextView) findViewById(R.id.tv_district); // provinceImageView = (ImageView) findViewById(R.id.iv_province); // cityImageView = (ImageView) findViewById(R.id.iv_city); // districtImageView = (ImageView) findViewById(R.id.iv_district); // // LayoutInflater inflater = LayoutInflater.from(this); // LinearLayout prvinceLayout = (LinearLayout) View.inflate(this, R.layout.popup_province, null); // provinceListView = (ListView) prvinceLayout.findViewById(R.id.lv_province); // mPopupWindow = new PopupWindow(prvinceLayout, 150, 280); // mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); // mPopupWindow.setFocusable(true); // mPopupWindow.setOutsideTouchable(true); // mPopupWindow.update(); // } // // private class ImageViewClickListener implements OnClickListener{ // // // @Override // public void onClick(View v) { // switch (v.getId()) { // case R.id.iv_province: // mPopupWindow.showAtLocation(mLinearLayout, Gravity.LEFT // | Gravity.TOP, arrayOfInt[0]+10, arrayOfInt[1]+41); // break; // case R.id.iv_city: // // break; // case R.id.iv_district: // // break; // // default: // break; // } // } // // } public void provinceSpinner(){ dbm.openDatabase(); db = dbm.getDatabase(); Cursor cursor=null; List provinces = new ArrayList(); try { String sql = "select * from province"; cursor = db.rawQuery(sql,null); while (cursor.moveToNext()){ String code=cursor.getString(cursor.getColumnIndex("code")); int id = cursor.getInt(cursor.getColumnIndex("id")); Log.i("tag", "id: "+id+"code: "+code); byte bytes[]=cursor.getBlob(2); String name=new String(bytes,"gbk"); CommonItem myListItem=new CommonItem(); myListItem.setName(name); myListItem.setPcode(code); provinces.add(myListItem); } Log.i("tag", "provinces size: "+provinces.size()); } catch (Exception e) { e.printStackTrace(); } finally{ dbm.closeDatabase(); db.close(); if (cursor!=null) { cursor.close(); } } CommonAdapter provinceAdapter = new CommonAdapter(this,provinces); provinceSpinner.setAdapter(provinceAdapter); } public void citySpinner(String pcode){ Cursor cursor = null; List citys = new ArrayList(); try { dbm.openDatabase(); db = dbm.getDatabase(); String sql = "select * from city where pcode='"+pcode+"'"; cursor = db.rawQuery(sql,null); while (cursor.moveToNext()){ String code=cursor.getString(cursor.getColumnIndex("code")); byte bytes[]=cursor.getBlob(2); String name=new String(bytes,"gbk"); CommonItem myListItem=new CommonItem(); myListItem.setName(name); myListItem.setPcode(code); citys.add(myListItem); } Log.i("tag", "citys size: "+citys.size()); } catch (Exception e) { e.printStackTrace(); } finally{ dbm.closeDatabase(); db.close(); if (cursor!=null) { cursor.close(); } } CommonAdapter cityAdapter = new CommonAdapter(this,citys); citySpinner.setAdapter(cityAdapter); } public void districtSpinner(String pcode){ Cursor cursor=null; List districts = new ArrayList(); try { dbm.openDatabase(); db = dbm.getDatabase(); String sql = "select * from district where pcode='"+pcode+"'"; cursor = db.rawQuery(sql,null); while (cursor.moveToNext()){ String code=cursor.getString(cursor.getColumnIndex("code")); byte bytes[]=cursor.getBlob(2); String name=new String(bytes,"gbk"); CommonItem myListItem=new CommonItem(); myListItem.setName(name); myListItem.setPcode(code); districts.add(myListItem); } Log.i("tag", "districts size: "+districts.size()); } catch (Exception e) { e.printStackTrace(); } finally{ dbm.closeDatabase(); db.close(); if (cursor!=null) { cursor.close(); } } CommonAdapter districtAdapter = new CommonAdapter(this,districts); districtSpinner.setAdapter(districtAdapter); } class ProvinceOnSelectedListener implements OnItemSelectedListener{ public void onItemSelected(AdapterView adapterView, View view, int position, long id) { province=((CommonItem) adapterView.getItemAtPosition(position)).getName(); String pcode =((CommonItem) adapterView.getItemAtPosition(position)).getPcode(); citySpinner(pcode); districtSpinner(pcode); } public void onNothingSelected(AdapterView adapterView) { } } class CityOnSelectedListener implements OnItemSelectedListener{ public void onItemSelected(AdapterView adapterView, View view, int position, long id) { city=((CommonItem) adapterView.getItemAtPosition(position)).getName(); String pcode =((CommonItem) adapterView.getItemAtPosition(position)).getPcode(); districtSpinner(pcode); } public void onNothingSelected(AdapterView adapterView) { } } class DistrictOnSelectedListener implements OnItemSelectedListener{ public void onItemSelected(AdapterView adapterView, View view, int position, long id) { district=((CommonItem) adapterView.getItemAtPosition(position)).getName(); Toast.makeText(City_cnActivity.this, province+" "+city+" "+district, Toast.LENGTH_LONG).show(); } public void onNothingSelected(AdapterView adapterView) { } } @Override protected void onDestroy() { dbm=null; super.onDestroy(); } }


【文件预览】:
city_cn
----.project(1KB)
----project.properties(361B)
----proguard.cfg(1KB)
----src()
--------cc()
----AndroidManifest.xml(733B)
----res()
--------raw()
--------drawable-ldpi()
--------drawable-hdpi()
--------drawable()
--------drawable-mdpi()
--------layout()
--------drawable-xhdpi()
--------values()
----.settings()
--------org.eclipse.wst.common.project.facet.core.xml(122B)
--------org.eclipse.jdt.core.prefs(364B)
--------org.eclipse.core.resources.prefs(88B)
----assets()
----gen()
--------cc()
----.classpath(700B)
----bin()
--------resources.ap_(53KB)
--------classes()
--------AndroidManifest.xml(733B)
--------dexedLibs()
--------jarlist.cache(119B)
--------res()
--------classes.dex(13KB)

网友评论