切换城市
package com.example.app_t; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity2 extends AppCompatActivity implements View.OnClickListener { Button Beijing,Shijiazhuang; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); GetControl(); } //按钮进行监听 @Override public void onClick(View view) { Intent intent = new Intent(); switch (view.getId()) { case R.id.beijing: intent.putExtra("name", "beijing"); break; case R.id.shijiazhuang: intent.putExtra("name", "shijiazhuang"); break; } intent.setClass(MainActivity2.this, MainActivity.class); startActivity(intent); } private void GetControl() { Beijing=findViewById(R.id.beijing); Shijiazhuang=findViewById(R.id.shijiazhuang); Beijing.setOnClickListener(this); Shijiazhuang.setOnClickListener(this); } }
线路站点查询
package com.example.app_t; import static com.example.app_t.unilt.ChangeChineseutils.getchinese; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import com.example.app_t.Dao.RouteDao; import com.example.app_t.pojo.Route; import com.example.app_t.pojo.Site; import java.util.List; import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class MainActivity extends AppCompatActivity implements View.OnClickListener { TextView textView1, textView2; EditText editText1, editText2; Button button1, button2, button3, button4, button5; String name; String Chance; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); GetControl(); Intent intent = getIntent(); name = intent.getStringExtra("name"); String Name = "城市地铁"; switch (name) { case "beijing": Name = "北京地铁"; Chance = "1"; break; case "shijiazhuang": Name = "石家庄地铁"; Chance = "2"; break; } textView1.setText(Name); } private void GetControl() { textView1 = findViewById(R.id.textview1); textView2 = findViewById(R.id.textview2); editText1 = findViewById(R.id.editText1); editText2 = findViewById(R.id.editText2); button1 = findViewById(R.id.button1); button1.setOnClickListener(this); button2 = findViewById(R.id.button2); button2.setOnClickListener(this); button3 = findViewById(R.id.button3); button3.setOnClickListener(this); button4 = findViewById(R.id.button4); button4.setOnClickListener(this); button5 = findViewById(R.id.button5); button5.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.button1: Intent intent1 = new Intent(); intent1.setClass(this, MainActivity2.class); startActivity(intent1); break; case R.id.button2: String Route = String.valueOf(editText1.getText()); try { List<Site> sites = ByRoute(Route, Chance); String str = ""; if (sites.size() != 0) { for (int i = 0; i < sites.size(); i++) { List<Route> routes = RouteByName(sites.get(i).getName(), Chance); if (routes.size() != 0) { str += "(换乘站)"; } str += sites.get(i).getName() + "\n"; } } else { str += "没有查找到相关信息,请重新输入!!!"; } textView2.setText(str); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } break; case R.id.button3: String Name = String.valueOf(editText2.getText()); try { List<Site> sites = ByName(Name, Chance); String str = ""; if (sites.size() != 0) { List<Route> routes = RouteByName(sites.get(0).getName(), Chance); if (routes.size() != 0) { str += "(换乘站)" + "\n"; } for (int i = 0; i < sites.size(); i++) { str += getchinese(sites.get(i).getRoute2()) + "\n"; } } else { str += "没有查找到相关信息,请重新输入!!!"; } textView2.setText(str); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } break; case R.id.button4: Intent intent4 = new Intent(); intent4.putExtra("name", name); intent4.setClass(this, MainActivity3.class); startActivity(intent4); break; case R.id.button5: Intent intent5 = new Intent(); intent5.putExtra("name", name); intent5.setClass(this, MainActivity4.class); startActivity(intent5); break; } } private static ExecutorService mExecutor = Executors.newSingleThreadExecutor(); public static List<Site> ByRoute(String Route, String Chance) throws InterruptedException, ExecutionException { Future<List<Site>> result2 = mExecutor.submit(new Callable<List<Site>>() { public List<Site> call() throws Exception { // TODO Auto-generated method stub return RouteDao.queryByRoute(Route, Chance); } }); return result2.get(); } public static List<Site> ByName(String Name, String Chance) throws InterruptedException, ExecutionException { Future<List<Site>> result2 = mExecutor.submit(new Callable<List<Site>>() { public List<Site> call() throws Exception { // TODO Auto-generated method stub return RouteDao.queryByName(Name, Chance); } }); return result2.get(); } public static List<Route> RouteByName(String Name, String Chance) throws InterruptedException, ExecutionException { Future<List<Route>> result2 = mExecutor.submit(new Callable<List<Route>>() { public List<Route> call() throws Exception { // TODO Auto-generated method stub return RouteDao.RouteByName(Name, Chance); } }); return result2.get(); } }
标签:总结,功能,String,Chance,3.22,Intent,new,import,id From: https://www.cnblogs.com/yetang307/p/17301678.html