首页 > 其他分享 >每日总结2023-03-25

每日总结2023-03-25

时间:2023-03-25 21:26:10浏览次数:38  
标签:03 show xian start 25 2023 test import android

今天进行了Android的北京地铁查询,代码量100行左右,

复制代码
package com.example.ditie;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

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

public class XianluActivity extends AppCompatActivity {
        private Button searchb;
        private EditText start,end;
        private TextView show_xian;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xianlu);

        searchb=findViewById(R.id.btn_search_for_x);
        start=findViewById(R.id.ed_start);
        end=findViewById(R.id.ed_end);
        show_xian=findViewById(R.id.tv_show_xian);

        searchb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s=start.getText().toString();
                String e=end.getText().toString();
                xianlufind(s,e);
            };

        });
    }

    private void xianlufind(String start,String end) {
        // 必须新开线程才能连接MySQL数据库
        new Thread(new Runnable() {
            @Override
            public void run() {
                String test="开始";
                List<String> list=new ArrayList<>();
                DbHelper dbHelper = new DbHelper();
                try {
                   list=dbHelper.result(start,end);
                    //test=dbHelper.find(1);
                    //Log.v("debug",test);
                    for (String string : list) {
                        test+="  "+string;
                        //show_xian.setText(show_xian.getText()+test);
                    }
                    show_xian.setText(show_xian.getText()+test);
                   // show_xian.setText(show_xian.getText()+test);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }
}
复制代码

 

下面为演示:

 

标签:03,show,xian,start,25,2023,test,import,android
From: https://www.cnblogs.com/JJTyyds/p/17255602.html

相关文章