实例介绍
【实例截图】
【核心代码】
package com.bus.shenyang.activity; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import com.bus.shenyang.R; import com.bus.shenyang.common.Bus; import com.bus.shenyang.database.BusDb; public class Transfer extends Activity { String[] sumb; BusDb dbfile; private SQLiteDatabase database; boolean state=true; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dbfile = new BusDb(this); dbfile.openDatabase(); dbfile.closeDatabase(); setContentView(R.layout.transfer); final EditText key1 = (EditText) this.findViewById(R.id.editText1); final EditText key2 = (EditText) this.findViewById(R.id.editText2); Button query = (Button) this.findViewById(R.id.button1); final TextView result = (TextView) this.findViewById(R.id.textView3); database = SQLiteDatabase.openOrCreateDatabase(BusDb.DB_PATH "/" BusDb.DB_NAME, null); query.setOnClickListener(new View.OnClickListener() { private int[] countx; private int[] county; int busstation1x, busstation1y; String[] LineStation1;// 经过这个站的所有站点 String[] LineStation2; String[] linkStation1; String[] linkStation2;// 一条线路的所有站点 String[] s1; String[] s2; private String strlineStation; private String busstation1; private String busstation2; private String[] LineStation3; private String[] LineStation4; private String[] LineStation33; private String[] LineStation44; @Override public void onClick(View v) { result.setText(" "); busstation1 = key1.getText().toString(); busstation2 = key2.getText().toString(); System.out.println("1111111111111"); Bus bus1 = chaxun(busstation1); Bus bus2 = chaxun(busstation2); System.out.println("bus1=" bus1); System.out.println("bus2=" bus2); if (bus1 == null || bus2 == null) { new AlertDialog.Builder(Transfer.this) .setTitle("提示") .setMessage("亲。。。。您输入的站点有误") .setPositiveButton("请输入", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }) .show(); } else { StringBuffer station1 = new StringBuffer(); String str33,str44; str33 = bus1.getLine(); str44 = bus2.getLine(); LineStation33 = str33.split("→"); LineStation44 = str44.split("→"); int LineAmount11 = LineStation33.length; int LineAmount22 = LineStation44.length; for (int index1 = 0; index1 < LineAmount11; index1 ) { for (int in1 = 0; in1 < LineAmount22; in1 ) { if(LineStation33[index1].equals(LineStation44[in1])) { station1.append(LineStation33[index1]); station1.append("或→"); state=false; System.out.println("二站点在同一线路上换乘的"); } } } result.setText("您输入的二站在同一条线路" station1.toString()); if(state) { System.out.println("二站点不在同一线路上换乘的"); String str1, str2,str3,str4; StringBuffer station = new StringBuffer(); str1 = bus1.getStation(); str2 = bus2.getStation(); str3 = bus1.getLine(); str4 = bus2.getLine(); LineStation1 = str1.split("→"); LineStation2 = str2.split("→"); LineStation3 = str3.split("→"); LineStation4 = str4.split("→"); int LineAmount1 = LineStation1.length; int LineAmount2 = LineStation2.length; for (int index = 0; index < LineAmount1; index ) { linkStation1 = LineStation1[index].split("、"); for (int in = 0; in < LineAmount2; in ) { linkStation2 = LineStation2[in].split("、"); strlineStation=Focus(linkStation1 ,linkStation2,LineStation3[index],LineStation4[in]); station.append(strlineStation); station.append("→"); } } result.setText(station.toString()); } } } private String Focus(String[] s1,String[] s2,String s3,String s4) { String stri =" "; String str3 = ""; String message=""; countx = new int[10]; county = new int[10]; int m, n, m1, n1, i, j, arry = 0; System.out.println(s1.length "!!!!!!!!!!!!" s2.length); for (i = 0; i < s1.length; i ) { for (j = 0; j < s2.length; j ) { if (s1[i].equals(s2[j])) { str3 = str3 s1[i]; message="乘坐" s3 "在" s1[i] "换乘" s4; System.out.println("乘坐" s3 "在" s1[i] "换乘" s4); System.out.println("i=" i "--j=" j); countx[arry] = i; county[arry] = j; arry ; } } } return message; } }); } protected Bus chaxun(String busstation) { Bus bus = new Bus(); StringBuffer lines = new StringBuffer(); StringBuffer station = new StringBuffer(); Cursor cursor = null; if (busstation != null && !busstation.equals("") && busstation.length() > 1) { cursor = database.rawQuery( "select id,line,time,station,opposite from bus_line where station like '%" busstation "%'", null); if (cursor.moveToNext()) { if (cursor.getColumnIndex("id") == 0 || cursor.getColumnIndex("id") == 1) { bus.setId(cursor.getInt(cursor.getColumnIndex("id"))); lines.append(cursor.getString(1)); lines.append("→"); station.append(cursor.getString(3)); station.append("→"); } while (cursor.moveToNext()) {// 迭代记录集 // cursor.moveToFirst(); bus.setId(cursor.getInt(cursor.getColumnIndex("id"))); System.out.println("id=" cursor.getInt(cursor.getColumnIndex("id"))); lines.append(cursor.getString(1)); lines.append("→"); station.append(cursor.getString(3)); station.append("→"); } bus.setLine(lines.toString()); bus.setStation(station.toString()); System.out.println("bus.getLine()=" bus.getLine()); System.out.println("bus.getStation()=" bus.getStation()); } else { bus = null; } } else { cursor = null; bus = null; } return bus; } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { new AlertDialog.Builder(Transfer.this) .setIcon(R.drawable.ic_launcher) .setTitle("沈阳离线公交") .setMessage("你确定退出了哦?") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { android.os.Process.killProcess(android.os.Process.myPid()); } }).setNegativeButton("取消", null).show(); return true; } else { return super.onKeyDown(keyCode, event); } } }
标签: 地图
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论