首页 > 其他分享 >第六周星期三每日总结

第六周星期三每日总结

时间:2023-03-22 22:44:15浏览次数:42  
标签:总结 cursor show tv 星期三 第六周 showx import android

    今日完成地铁查询系统android端线路查询功能的开发,站点查询可参考此查询方式。但是此查询方式仍有不足,比如会遇到查询信息过长界面不能完全显示导致的软件闪退,期望再后面的开发中能通过添加滚动条的方式解决。

查询结果图:

 

 

 查询代码:

 1 package com.example.test1;
 2 import android.content.Intent;
 3 import android.database.Cursor;
 4 import android.database.sqlite.SQLiteDatabase;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 import android.widget.Button;
 8 import android.widget.EditText;
 9 import android.widget.TextView;
10 import android.widget.Toast;
11 
12 import androidx.appcompat.app.AppCompatActivity;
13 
14 public class ScreachFirstActivity extends AppCompatActivity {
15     final Mysql dbHelper = new Mysql(this,"subway",null,2);
16     private Button searchButton;
17     private EditText search;
18     private TextView tv_show, tv_showx;
19 
20     @Override
21     protected void onCreate(Bundle savedInstanceState) {
22         super.onCreate(savedInstanceState);
23         setContentView(R.layout.activity_screach_first);
24         searchButton = findViewById(R.id.btn_choice1);
25         search = findViewById(R.id.search);
26         tv_show = findViewById(R.id.tv_show);
27         tv_showx = findViewById(R.id.tv_showx);
28         searchButton.setOnClickListener(new View.OnClickListener() {
29             @Override
30             public void onClick(View v) {
31                 SQLiteDatabase db = dbHelper.getWritableDatabase();
32                 String n_search = search.getText().toString();
33                 if (n_search.equals("")) {
34                     myShow();
35                     db.close();
36                 } else {
37                     tv_show.setText("线路号");
38                     tv_showx.setText("站名");
39                     Cursor cursor = db.rawQuery("select * from bj_subway where line_name = ? ", new String[]{n_search});
40 
41                     while (cursor.moveToNext()) {
42                         String l = cursor.getString(1);
43                         String x = cursor.getString(2);
44                         tv_show.setText(tv_show.getText() + "\n" + l);
45                         tv_showx.setText(tv_showx.getText() + "\n" + x);
46                     }
47 
48                     cursor.close();
49                     db.close();
50                 }
51             }
52         });
53     }
54     public void myShow() {
55         SQLiteDatabase db = dbHelper.getReadableDatabase();
56         tv_show.setText("线路号");
57         tv_showx.setText("站名");
58         Cursor cursor = db.rawQuery("select * from  bj_subway", null);
59 
60         while (cursor.moveToNext()) {
61             String l = cursor.getString(1);
62             String x = cursor.getString(2);
63             tv_show.setText(tv_show.getText() + "\n" + l);
64             tv_showx.setText(tv_showx.getText() + "\n" + x);
65         }
66     }
67 }

此代码在查询时遇到能够查询到数据但是下方数据库显示数据库未打开问题,此情况需要重启软件即可解决。

 

标签:总结,cursor,show,tv,星期三,第六周,showx,import,android
From: https://www.cnblogs.com/sgle0722/p/17245772.html

相关文章

  • 2023.3.22三天学习总结
    一.三天任务1.费用流的学习和练习2.dp练习3.cf补题和abc补题4.补了一些以前题目的题解二.补题情况   三.题解(174条消息)图论习......
  • 3.22 每日总结
    今天进行了Android的第三步的的线路查询输出,并进行了最短路径的线路查询算法学习。  进行了网站搜索地图的api设置。进行了学习。对算法的进行明天进行分析。......
  • 每日总结2023/3/22
    今天进行了Android的第三步的的线路查询输出,并进行了最短路径的线路查询算法学习。  进行了网站搜索地图的api设置。进行了学习。对算法的进行明天进行分析。......
  • 今日总结-31
    今日打卡所花时间(包括上课):4h代码量(行):300发表博客:2篇(不包括本篇)学习进度和了解到的知识点:今天完善了web版的地铁查询系统,已经基本上完善完毕。开始着手做Android的最......
  • 每日总结19
     像素单位大小  像素计算 ......
  • 2023.3.22每日总结
    importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassT......
  • 2023、03、22学习总结
    完成了app的页面设计 ......
  • 算法总结--动态规划
    声明(叠甲):鄙人水平有限,本文为作者的学习总结,仅供参考。1.动态规划介绍动态规划,英文:DynamicProgramming,简称DP,如果某一问题有很多重叠子问题,使用动态规划是最有效的......
  • 3.22总结
    <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>Inserttitleh......
  • 2022年总结之 禅道团队扩张篇
    这是和Amy赌约的第一篇文章。2023年我们约定每周要发一篇不少于800字的文章。我比较喜欢3号,我的第一篇文章就从2023年1月3号开始(首发于公众号:代码之歌)。第一篇文章就来总结......