首页 > 其他分享 >地铁查询

地铁查询

时间:2023-06-10 11:26:33浏览次数:31  
标签:String 查询 cursor 地铁 import line public firstline

package com.example.subway1;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import database.DBHelper;

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

public class ByPointActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText et_Point;
    private TextView tv_showPoint;
    private DBHelper mHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_by_point);
        et_Point=findViewById(R.id.et_Point);
        tv_showPoint=findViewById(R.id.tv_showPoint);
        findViewById(R.id.bt_ByPoint1).setOnClickListener(this);
    }
    protected void onStart() {
        super.onStart();
        mHelper=DBHelper.getInstance(this);
        mHelper.openWriteLink();
        mHelper.openReadLink();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHelper.closeLink();
    }
    @Override
    public void onClick(View view) {
        List<String> list=mHelper.find3(et_Point.getText().toString());
        StringBuffer buffer=new StringBuffer();
        if(list.size()==0){
            tv_showPoint.setText("没有结果");
        }else {
            for (int i=0;i<list.size();i++){
                buffer.append("线路:"+list.get(i)+"\n");
            }
            tv_showPoint.setText(buffer);
        }
    }
}
package com.example.subway1;

import android.content.Intent;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.bt_ByLine).setOnClickListener(this);
        findViewById(R.id.bt_ByPoint).setOnClickListener(this);
        findViewById(R.id.bt_extreme).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_ByLine:
                startActivity(new Intent(this,ByLineActivity.class));
                break;
            case R.id.bt_ByPoint:
                startActivity(new Intent(this,ByPointActivity.class));
                break;
            case R.id.bt_extreme:
                startActivity(new Intent(this,ByExtremeActivity.class));
                break;
        }
    }
}
package database;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.List;
import entity.Line;

public class DBHelper extends SQLiteOpenHelper {
    private static final String DB_NAME="sub.db";
    private static final String TABLE_NAME="firstline";
    private static final String TABLE_NAME1="changeline";
    private static final int DB_VERSION=1;
    private static DBHelper mHelper=null;
    private SQLiteDatabase mRDB=null;
    private SQLiteDatabase mWDB=null;
    ArrayList<String> array=new ArrayList<String>();

    private DBHelper(Context context){
        super(context,DB_NAME,null,DB_VERSION);
    }
    public static DBHelper getInstance(Context context){
        if(mHelper==null)
        {
            mHelper=new DBHelper(context);
        }
        return mHelper;
    }
    public SQLiteDatabase openReadLink(){
        if(mRDB==null||!mRDB.isOpen())
        {
            mRDB=mHelper.getReadableDatabase();
        }
        return mRDB;
    }
    public SQLiteDatabase openWriteLink(){
        if(mWDB==null||!mWDB.isOpen())
        {
            mWDB=mHelper.getWritableDatabase();
        }
        return mWDB;
    }
    public void closeLink(){
        if(mRDB!=null&&mRDB.isOpen())
        {
            mRDB.close();
            mRDB=null;
        }
        if(mWDB!=null&&mWDB.isOpen())
        {
            mWDB.close();
            mWDB=null;
        }
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql="CREATE TABLE IF NOT EXISTS "+TABLE_NAME+"("+
                " StopID VARCHAR NOT NULL,"+
                " StopName VARCHAR NOT NULL,"+
                " Line VARCHAR NOT NULL)";
        db.execSQL(sql);
        sql="CREATE TABLE IF NOT EXISTS "+TABLE_NAME1+"("+
                " ID1 VARCHAR NOT NULL,"+
                " ID2 VARCHAR NOT NULL,"+
                " ChangeStopName VARCHAR NOT NULL)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
    public List<String> find3(String linepoint){
        List<String>list=new ArrayList<>();
        Cursor cursor=mRDB.query(TABLE_NAME,null,"StopName=?",new String[]{linepoint},null,null,null);
            while (cursor.moveToNext()) {
                String s=cursor.getString(2);
                list.add(s+" ");
            }
        return list;
    }
    public List<String> find1(String line){
        List<String>list=new ArrayList<>();
            Cursor cursor=mRDB.query(TABLE_NAME,null,"Line=?",new String[]{line},null,null,null);
            while (cursor.moveToNext()) {
                String s = cursor.getString(1);
                list.add(s);
            }
                return list;
            }
    public int CheckAll(Line line)  {
        int checkall=0;
        Cursor cursor=mRDB.rawQuery("SELECT * FROM firstline f1 JOIN firstline f2 on f1.Line=f2.Line WHERE f1.StopName=? AND f2.StopName=?",new String[]{line.getStartstopname(),line.getEndstopname()});
        while(cursor.moveToNext()){
            line.setTemporaryline(cursor.getInt(2));
        }
        if(line.getTemporaryline()!=0) {
            checkall=1;
            return checkall;
        }
        else if(line.getTemporaryline()==0){
            cursor=mRDB.rawQuery("select * from firstline where StopName='"+line.getStartstopname()+"' or StopName='"+line.getEndstopname()+"'",null);
            while(cursor.moveToNext()) {
                if(line.getStartstopname().equals(cursor.getString(1)))
                {
                    line.setOriginline(cursor.getInt(2));
                }
                if(line.getEndstopname().equals(cursor.getString(1))) {
                    line.setFinishline(cursor.getInt(2));
                }
            }
            if(line.getOriginline()==0||line.getFinishline()==0) {
                checkall=4;
                return checkall;
            }
            cursor=mRDB.rawQuery("select * from changeline where ID1='"+line.getOriginline()+"' and ID2='"+line.getFinishline()+"'",null);
            while(cursor.moveToNext()) {
                line.setMiddlestop(cursor.getString(2));
            }
            if(line.getMiddlestop().equals("")) {
                checkall=3;
                return checkall;
            }
            else {
                checkall=2;
                return checkall;
            }
        }
        return checkall;

    }
    public ArrayList<String> Connectonlyoneline(Line line)
    {
        ArrayList<String> array1=new ArrayList<String>();
        int c=0;
        try {
            Cursor cursor=mRDB.rawQuery("SELECT * FROM firstline f1 JOIN firstline f2 on f1.Line=f2.Line WHERE f1.StopName='"+line.getStartstopname()+"' AND f2.StopName='"+line.getEndstopname()+"'",null);
            while(cursor.moveToNext()) {
                line.setTemporaryline(cursor.getInt(2));
            }
            System.out.println(line.getTemporaryline());
            array.add(" 地铁"+line.getTemporaryline()+"号线");
            c=select(line);
            System.out.println(c);
            if(c==1)
            {
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {
                    array.add(cursor.getString(1));
                }
            }
            else if(c==2)
            {
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {
                    array1.add(cursor.getString(1));
                }
                for(int i=0;i<array1.size();i++)
                {
                    System.out.print(array1.get(i)+" ");
                }
                for(int j=array1.size()-1;j>=0;j--)
                {
                    array.add(array1.get(j));
                }
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } finally {
            line.setArray(array);
            for(int i=0;i<array.size();i++) {
                System.out.println(array.get(i)+" ");
            }
        }
        return array;
    }
    public int select(Line line) throws ClassNotFoundException {
        int i=0;
        Cursor cursor=mRDB.rawQuery("select * from firstline where StopName='"+line.getStartstopname()+"'and Line='"+line.getTemporaryline()+"' or StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"'",null);
            while(cursor.moveToNext()) {
                if(line.getStartstopname().equals(cursor.getString(1)))
                {
                    line.setStartstopID(cursor.getInt(0));
                }
                if(line.getEndstopname().equals(cursor.getString(1))) {
                    line.setEndstopID(cursor.getInt(0));
                }
            }
        System.out.println(line.getStartstopID()+" "+line.getEndstopID());
        if(line.getStartstopID()<line.getEndstopID()) {
            i=1;
            return i;
        }
        else {
            i=2;
            return i;
        }
    }
    public ArrayList<String> Connecttwoline(Line line) throws ClassNotFoundException{
        int c=0;
        same(line);
        Cursor cursor=mRDB.rawQuery("select * from changeline where ID1='"+line.getOriginline()+"' and ID2='"+line.getFinishline()+"'",null);
        while(cursor.moveToNext()) {
            line.setMiddlestop(cursor.getString(2));
        }
        line.setTemporarystartstopname(line.getStartstopname());
        line.setTemporaryendstopname(line.getEndstopname());
        cursor=mRDB.rawQuery("select * from firstline where Line='"+line.getOriginline()+"' and StopName='"+line.getMiddlestop()+"'",null);
        while(cursor.moveToNext()) {
            line.setEndstopname(cursor.getString(1));
        }
        line.setStartstopname(line.getTemporarystartstopname());
        line.setTemporaryline(line.getOriginline());
        array.add("地铁"+line.getOriginline()+"号线");
        c=select(line);
        if(c==1)
        {
            cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
            while(cursor.moveToNext())
            {
                array.add(cursor.getString(1));
            }
        }
        else if(c==2)
        {
            ArrayList<String> array1=new ArrayList<String>();
            cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
            while(cursor.moveToNext())
            {
                array1.add(cursor.getString(1));
            }
            for(int i=0;i<array1.size();i++)
            {
                System.out.print(array1.get(i)+" ");
            }
            for(int j=array1.size()-1;j>=0;j--)
            {
                array.add(array1.get(j));
            }
        }
        array.add("换乘"+line.getFinishline()+"号线");
        line.setStartstopname(line.getMiddlestop());
        line.setEndstopname(line.getTemporaryendstopname());
        line.setTemporaryline(line.getFinishline());
        c=select(line);
        if(c==1)
        {
            cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
            while(cursor.moveToNext())
            {//���������
                array.add(cursor.getString(1));
            }
        }
        else if(c==2)
        {//��ʼվ��Ŵ����յ�վ������ʼվ�ں��յ�վ��ǰ
            ArrayList<String> array1=new ArrayList<String>();
            cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
            while(cursor.moveToNext())
            {
                array1.add(cursor.getString(1));
            }
            for(int i=0;i<array1.size();i++)
            {
                System.out.print(array1.get(i)+" ");
            }
            for(int j=array1.size()-1;j>=0;j--)
            {
                array.add(array1.get(j));
            }
        }
        return array;

    }
    public int same(Line line)  {
        int checksameline=0;
        Cursor cursor=mRDB.rawQuery("select * from firstline where StopName='"+line.getStartstopname()+"' or StopName='"+line.getEndstopname()+"'",null);
        while(cursor.moveToNext()) {
            if(line.getStartstopname().equals(cursor.getString(1)))
            {
                line.setOriginline(cursor.getInt(2));
            }
            if(line.getEndstopname().equals(cursor.getString(1))) {
                line.setFinishline(cursor.getInt(2));
            }
        }
        if(line.getFinishline()==line.getOriginline()) {//��ͬһ����
            checksameline=1;
            return checksameline;
        }
        else {//����ͬһ����
            checksameline=2;
            return checksameline;
        }
    }
    public ArrayList<String> Connectthreeline(Line line) throws ClassNotFoundException {
        ArrayList<Integer> array1=new ArrayList<Integer>();
        int c=0;
        int min=0;
        same(line);
        Cursor cursor=mRDB.rawQuery("SELECT    * FROM    changeline c1 JOIN changeline c2 ON c1.ID2 = c2.ID1 WHERE trim(c1.ChangeStopName) != '' AND trim(c2.ChangeStopName) != '' AND c1.ID1 = '"+line.getOriginline()+"' AND c2.ID2 = '"+line.getFinishline()+"'",null);
        while(cursor.moveToNext())
        {
            if(line.getOriginline()==cursor.getInt(0))
            {
                array1.add(cursor.getInt(1));
            }
        }
        line.setTemporarystartstopname(line.getStartstopname());
        line.setTemporaryendstopname(line.getEndstopname());
        for(int j=0;j<array1.size();j++)
        {
            ArrayList<String> array3=new ArrayList<String>();

            System.out.println("Ҳ����������Ҫ����ʼվ"+line.getTemporarystartstopname());
            cursor=mRDB.rawQuery("select * from changeline where ID1='"+line.getOriginline()+"' and ID2='"+array1.get(j)+"'",null);
            while(cursor.moveToNext())
            {
                line.setEndstopname(cursor.getString(2));
            }
            array3.add("����"+line.getOriginline()+"����");
            array3.add(line.getTemporarystartstopname());
            cursor=mRDB.rawQuery("SELECT * FROM firstline f1 JOIN firstline f2 on f1.Line=f2.Line WHERE f1.StopName='"+line.getStartstopname()+"' AND f2.StopName='"+line.getEndstopname()+"'",null);
            //��֤������תվ��ͬһ����·��
            while(cursor.moveToNext()) {
                line.setTemporaryline(cursor.getInt(2));
            }
            c=select(line);
            if(c==1)
            {
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {//���������
                    array3.add(cursor.getString(1));
                }
            }
            else if(c==2)
            {//��ʼվ��Ŵ����յ�վ������ʼվ�ں��յ�վ��ǰ
                ArrayList<String> array2=new ArrayList<String>();
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {
                    array2.add(cursor.getString(1));
                }
                for(int i=0;i<array2.size();i++)
                {//�����Ƿ���ֵ
                    System.out.print(array2.get(i)+" ");
                }
                for(int i=array2.size()-1;i>=0;i--)
                {//��վ��������
                    array3.add(array2.get(i));
                }
            }
            line.setStartstopname(line.getEndstopname());
            cursor=mRDB.rawQuery("select * from changeline where ID1='"+array1.get(j)+"' and ID2='"+line.getFinishline()+"'",null);
            while(cursor.moveToNext())
            {
                line.setEndstopname(cursor.getString(2));
            }
            cursor=mRDB.rawQuery("SELECT * FROM firstline f1 JOIN firstline f2 on f1.Line=f2.Line WHERE f1.StopName='"+line.getStartstopname()+"' AND f2.StopName='"+line.getEndstopname()+"'",null);
            while(cursor.moveToNext()) {
                line.setTemporaryline(cursor.getInt(2));
            }
            array3.add("ת��"+line.getTemporaryline()+"����");
            c=select(line);
            if(c==1)
            {
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {
                    array3.add(cursor.getString(1));
                }
            }
            else if(c==2)
            {
                ArrayList<String> array2=new ArrayList<String>();
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {
                    array2.add(cursor.getString(1));
                }
                for(int i=0;i<array2.size();i++)
                {
                    System.out.print(array2.get(i)+" ");
                }
                for(int i=array2.size()-1;i>=0;i--)
                {
                    array3.add(array2.get(i));
                }
            }
            line.setStartstopname(line.getEndstopname());
            line.setEndstopname(line.getTemporaryendstopname());
            cursor=mRDB.rawQuery("SELECT * FROM firstline f1 JOIN firstline f2 on f1.Line=f2.Line WHERE f1.StopName='"+line.getStartstopname()+"' AND f2.StopName='"+line.getEndstopname()+"'",null);
            while(cursor.moveToNext()) {
                line.setTemporaryline(cursor.getInt(2));
            }
            array3.add("ת��"+line.getTemporaryline()+"����");
            c=select(line);
            if(c==1)
            {
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {
                    array3.add(cursor.getString(1));
                }
            }
            else if(c==2)
            {
                ArrayList<String> array2=new ArrayList<String>();
                cursor=mRDB.rawQuery("select * from firstline where StopID>=(select StopID from firstline where StopName='"+line.getEndstopname()+"' and Line='"+line.getTemporaryline()+"') and StopID<=(select StopID from firstline where StopName='"+line.getStartstopname()+"' and Line='"+line.getTemporaryline()+"')",null);
                while(cursor.moveToNext())
                {
                    array2.add(cursor.getString(1));
                }
                for(int i=0;i<array2.size();i++)
                {
                    System.out.print(array2.get(i)+" ");
                }
                for(int i=array2.size()-1;i>=0;i--)
                {
                    array3.add(array2.get(i));
                }
            }
            if(j==0) {
                min=array3.size();
            }
            System.out.println();
            System.out.println();
            for(int x=0;x<array3.size();x++) {
                System.out.print(array3.get(x)+" ");

            }
            System.out.println();
            System.out.println(min);
            if(min>=array3.size()) {
                min=array3.size();
                for(int x=0;x<array3.size();x++) {
                    System.out.print(array3.get(x)+" ");

                }
                array=array3;
            }
        }

        return array;

    }
}
package com.example.subway1;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import database.DBHelper;
import entity.Line;

import java.sql.SQLException;
import java.util.ArrayList;

public class ByExtremeActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText et_Star;
    private EditText et_Stop;
    private TextView tv_showExtreme;
    private DBHelper mHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_by_extreme);
        et_Star=findViewById(R.id.et_Star);
        et_Stop=findViewById(R.id.et_Stop);
        tv_showExtreme=findViewById(R.id.tv_showExtreme);
        findViewById(R.id.bt_ByExtreme1).setOnClickListener(this);
    }
    protected void onStart() {
        super.onStart();
        mHelper=DBHelper.getInstance(this);
        mHelper.openWriteLink();
        mHelper.openReadLink();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHelper.closeLink();
    }
    @Override
    public void onClick(View view) {
        Line line = new Line();
        StringBuffer buffer=new StringBuffer();
        ArrayList<String> array = new ArrayList<String>();
        line.setStartstopname(et_Star.getText().toString());
        line.setEndstopname(et_Stop.getText().toString());
        int x = mHelper.CheckAll(line);
        buffer.append(x+"\n");
        tv_showExtreme.setText(buffer);
        buffer=new StringBuffer();
        if (x == 1) {
            array = mHelper.Connectonlyoneline(line);
        } else if (x == 2) {
            try {
                array = mHelper.Connecttwoline(line);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        } else if (x == 3) {
            try {
                array = mHelper.Connectthreeline(line);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        } else {
            Toast.makeText(this, "有错误", Toast.LENGTH_SHORT).show();
        }
        for (int i=0;i<array.size();i++){
            buffer.append(array.get(i)+"\n");
        }
        tv_showExtreme.setText(buffer);
    }
}
package com.example.subway1;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import database.DBHelper;

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

public class ByPointActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText et_Point;
    private TextView tv_showPoint;
    private DBHelper mHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_by_point);
        et_Point=findViewById(R.id.et_Point);
        tv_showPoint=findViewById(R.id.tv_showPoint);
        findViewById(R.id.bt_ByPoint1).setOnClickListener(this);
    }
    protected void onStart() {
        super.onStart();
        mHelper=DBHelper.getInstance(this);
        mHelper.openWriteLink();
        mHelper.openReadLink();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHelper.closeLink();
    }
    @Override
    public void onClick(View view) {
        List<String> list=mHelper.find3(et_Point.getText().toString());
        StringBuffer buffer=new StringBuffer();
        if(list.size()==0){
            tv_showPoint.setText("没有结果");
        }else {
            for (int i=0;i<list.size();i++){
                buffer.append("线路:"+list.get(i)+"\n");
            }
            tv_showPoint.setText(buffer);
        }
    }
}
package entity;

import java.util.ArrayList;

public class Line {
    private String startstopname;//��ʼվվ��
    private String endstopname;//����վվ��
    private int startstopID;//    ��ʼվվ���
    private int endstopID;//����վվ���
    private String startline1=null;//��ʼ��ĵ�һ����
    private String startline2=null;//��ʼ��ڶ�����
    private String endline1=null;//������ĵ�һ����
    private String endline2=null;//������ĵڶ�����
    private ArrayList<String> array = new ArrayList<String>();//��Ź���վ��
    private int originline;//��ʼվ������·
    private int finishline;//������������·
    private String middlestop;//��תվվ��
    private String temporarystartstopname;//��ʱ��ʼվ������
    private String temporaryendstopname;//��ʱ�յ�վ������
    private int temporaryline=0;//��ʱ��·
    public Line() {

    }
    public int getTemporaryline() {
        return temporaryline;
    }
    public void setTemporaryline(int temporaryline) {
        this.temporaryline = temporaryline;
    }
    public String getTemporarystartstopname() {
        return temporarystartstopname;
    }
    public void setTemporarystartstopname(String temporarystartstopname) {
        this.temporarystartstopname = temporarystartstopname;
    }
    public String getTemporaryendstopname() {
        return temporaryendstopname;
    }
    public void setTemporaryendstopname(String temporaryendstopname) {
        this.temporaryendstopname = temporaryendstopname;
    }
    public String getMiddlestop() {
        return middlestop;
    }
    public void setMiddlestop(String middlestop) {
        this.middlestop = middlestop;
    }
    public int getOriginline() {
        return originline;
    }
    public void setOriginline(int originline) {
        this.originline = originline;
    }
    public int getFinishline() {
        return finishline;
    }
    public void setFinishline(int finishline) {
        this.finishline = finishline;
    }
    public ArrayList<String> getArray() {
        return array;
    }
    public void setArray(ArrayList<String> array) {
        this.array = array;
    }
    public String getStartline1() {
        return startline1;
    }
    public void setStartline1(String startline1) {
        this.startline1 = startline1;
    }
    public String getStartline2() {
        return startline2;
    }
    public void setStartline2(String startline2) {
        this.startline2 = startline2;
    }
    public String getEndline1() {
        return endline1;
    }
    public void setEndline1(String endline1) {
        this.endline1 = endline1;
    }
    public String getEndline2() {
        return endline2;
    }
    public void setEndline2(String endline2) {
        this.endline2 = endline2;
    }
    public String getStartstopname() {
        return startstopname;
    }
    public void setStartstopname(String startstopname) {
        this.startstopname = startstopname;
    }
    public String getEndstopname() {
        return endstopname;
    }
    public void setEndstopname(String endstopname) {
        this.endstopname = endstopname;
    }
    public int getStartstopID() {
        return startstopID;
    }
    public void setStartstopID(int startstopID) {
        this.startstopID = startstopID;
    }
    public int getEndstopID() {
        return endstopID;
    }
    public void setEndstopID(int endstopID) {
        this.endstopID = endstopID;
    }

    @Override
    public String toString() {
        return "Line{" +
                "startstopname='" + startstopname + '\'' +
                ", endstopname='" + endstopname + '\'' +
                ", startstopID=" + startstopID +
                ", endstopID=" + endstopID +
                ", startline1='" + startline1 + '\'' +
                ", startline2='" + startline2 + '\'' +
                ", endline1='" + endline1 + '\'' +
                ", endline2='" + endline2 + '\'' +
                ", array=" + array +
                ", originline=" + originline +
                ", finishline=" + finishline +
                ", middlestop='" + middlestop + '\'' +
                ", temporarystartstopname='" + temporarystartstopname + '\'' +
                ", temporaryendstopname='" + temporaryendstopname + '\'' +
                ", temporaryline=" + temporaryline +
                '}';
    }
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ByExtremeActivity"
        android:orientation="vertical"
>
    <LinearLayout android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:orientation="vertical">
    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="horizontal"
                  android:layout_marginTop="20dp"
    >
        <EditText android:layout_width="197dp"
                  android:layout_height="69dp"
                  android:layout_marginLeft="5dp"
                  android:id="@+id/et_Star"
        />
        <EditText android:layout_width="189dp"
                  android:layout_height="match_parent"
                  android:layout_marginLeft="10dp"
                  android:id="@+id/et_Stop"

        />
    </LinearLayout>
    <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="查询"
            android:id="@+id/bt_ByExtreme1"
    />
        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/tv_showExtreme"
                  android:layout_below="@id/bt_ByExtreme1"
                  android:textColor="@color/black"
                  android:textSize="20sp"
        />
    </LinearLayout>


</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ByLineActivity"
        android:orientation="vertical"
>
    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"
    >
    <EditText android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/et_Line"
              />

    <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="查询"
            android:id="@+id/bt_ByLine1"
    />

        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/tv_showLine"
                  android:layout_below="@id/bt_ByLine1"
                  android:textColor="@color/black"
                  android:textSize="20sp"
        />
    </LinearLayout>

</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ByPointActivity"
        android:orientation="vertical"
>
    <EditText android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/et_Point"
              android:layout_marginTop="5dp"
    />
    <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="查询"
            android:id="@+id/bt_ByPoint1"
    />
        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/tv_showPoint"
                  android:layout_below="@id/bt_ByPoint1"
                  android:textColor="@color/black"
                  android:textSize="20sp"
        />




</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical"
>
    <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="按线路查询"
            android:layout_marginTop="200dp"
            android:id="@+id/bt_ByLine"
    />
    <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="站点查询"
            android:layout_marginTop="10dp"
            android:id="@+id/bt_ByPoint"
    />
    <Button android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="起点,终点查询"
            android:layout_marginTop="10dp"
            android:id="@+id/bt_extreme"
    />


</LinearLayout>

 

标签:String,查询,cursor,地铁,import,line,public,firstline
From: https://www.cnblogs.com/zzfdbk/p/17470935.html

相关文章

  • ms sql 表 索引查询
    SELECTOBJECT_NAME(IDX.object_id)Table_Name,IDX.nameIndex_name ,PAR.rowsNumOfRows ,IDX.type_descTypeOfIndexFROMsys.partitionsPARINNERJOINsys.indexesIDXONPAR.object_id=IDX.object_idANDPAR.index_id=IDX.index_idANDIDX.type......
  • ArcEngine|空间查询功能
    所有的代码已经传到了我的GitHub,需要的请自取,GitHub项目地址:https://github.com/weltme/T_ArcMap(1)界面设计(2)思路​ 就实现细节而言,实例通过ISpatialFilter接口来定义空间查询条件,其Geometry属性确定用来查询的空间几何体,SpatialRel属性定义查询所使用的所有空间关系,为esr......
  • Nest.js + TypeOrm:原始SQL查询及其参数绑定
    上一篇Nest.js+TypeOrm:安装、编写实体类参数化原始SQL查询使用DataSource,注意,如果是PostgreSQL,则参数占位符不能使用问号?,只能使用$n,并且在没有表名的情况下需要指定类型:否则,会出现错误:PostgreSQL-ERROR:couldnotdeterminedatatypeofparameter$1,参见:https://b......
  • MySQL中查询第2-5条记录的语句为
    查询第m行到第n行记录,注意表中的记录下标是从0开始的,就像数组一样select*fromstudentlimitm,n;返回m+1到m+n行记录,m代表开始的下标,n代表查找的结果数,将返回n行结果select*fromstudentlimit2,8;返回3到10行记录 ......
  • 02-mysql高级-约束(主键,外键,非空,唯一,默认)、设计(一对多,多对多)、多表查询(内连接
    文章目录mysql高级1,约束1.1概念1.2分类1.3非空约束1.4唯一约束1.5主键约束1.6默认约束1.7约束练习1.8外键约束1.8.1概述1.8.2语法1.8.3练习2,数据库设计2.1数据库设计简介2.2表关系(一对多)2.3表关系(多对多)2.4表关系(一对一)2.5数据库设计案例**LX:**3,多表查询3.......
  • Hibernate_根据条件动态组装sql/hql语句(仿ibatis动态查询语句功能)
     1.功能需求背景 项目中使用hibernate作为数据持久层框架,主要考虑hibernate在进行一些简单的crud操作时非常便利,不需要和ibatis似的为每个sql操作都写一堆文件,但是同时也带来了一些局限性,如类似ibatis强大的动态查询功能用不了了,但是这个功能在项目中的应用场景又很大,hibernate......
  • python - sqlite查询表名 列名
    最近在看到一个之前做的sqlite数据库时发现忘了table名叫什么了,所以找了找发现可以直接用python查询,记录一下importsqlite3conn=sqlite3.connect('test.db')cur=conn.cursor()sql="select*fromsqlite_masterwheretype='table'"cur.execute(sql)print(cur.fetcha......
  • mysql 查询语句
    一、mysql查询的五种子句    where(条件查询)、having(筛选)、groupby(分组)、orderby(排序)、limit(限制结果数)   1、where常用运算符:      比较运算符        >, < , = , !=(<>), >= , <=         i......
  • django中的Case,When查询
    这一篇笔记将介绍条件表达式,就是如何在model的使用中根据不同的条件筛选数据返回。这个操作类似于数据库中ifelifelse的逻辑。1、model和数据准备这篇笔记我们用到的model是Client,放在blog/models.py下classClient(models.Model):REGULAR='R'GOLD=......
  • 联接查询更新
    Oracle实现多表参照更新参照T2修改T1表1表2方法1updatestudentsetgrade=(selectgradefromgradedetialwheresid=student.idandrownum=1)whereexists(selectcount(1)fromgradedetialwheresid=student.id)如果同时更新多个字段可以参照语法:upd......