开发工具:
文件大小: 135kb
下载次数: 0
上传时间: 2014-12-28
详细说明: 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.widge t.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(); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.