5.19
所花时间:3小时
代码量:106
博客篇:1
政策查询Android端实现
Dao
package com.example.policy.javaClass; import android.util.Log; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; public class Dao { private Connection conn = null; private Statement stmt; public ArrayList<Policy> check(String viadata, String range, String type, String text) throws SQLException { conn = DBHelpOpen.getConn(); stmt = conn.createStatement(); ArrayList<Policy> a = new ArrayList<>(500); String sql = "select * from policy where viadata like '%"+viadata+"%' and 'range' like '%"+range+"%' and type like '%"+type+"%' and text like '%"+text+"%'"; ResultSet rs = stmt.executeQuery(sql); int i=0; while (rs.next()) { Policy p =new Policy(); p.setName(rs.getString("name")); p.setOrgan(rs.getString("organ")); p.setViadata(rs.getString("viadata")); p.setText(rs.getString("text")); p.setType(rs.getString("type")); a.add(p); } stmt.close(); conn.close(); return a; } }
acticity_check
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".checkActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/ed_check" android:layout_width="326dp" android:layout_height="wrap_content" android:hint="标题、内容、关键字"/> <Button android:id="@+id/bt_check" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/black" android:text="搜索"/> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="40dp" android:textColor="@color/black" android:text="时间"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="近一周" android:textSize="30sp"/> <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="近一月" android:textSize="30sp"/> <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="近一年" android:textSize="30sp"/> </RadioGroup> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="40dp" android:textColor="@color/black" android:text="施行范围"/> <Spinner android:id="@+id/sp_range" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbarSize="30dp" android:entries="@array/range"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="40dp" android:textColor="@color/black" android:text="政策类型"/> <TextView android:id="@+id/tv_type" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20dp" android:text="请选择" android:drawableRight="@drawable/baseline_arrow_back_ios_new_24"/> </LinearLayout>
acticity_main
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="?attr/actionBarSize"> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/nav_view" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="0dp" android:layout_marginEnd="0dp" android:background="?android:attr/windowBackground" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:menu="@menu/bottom_nav_menu" /> <fragment android:id="@+id/nav_host_fragment_activity_main" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" app:layout_constraintBottom_toTopOf="@id/nav_view" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:navGraph="@navigation/mobile_navigation" /> </androidx.constraintlayout.widget.ConstraintLayout>
acticity_policy
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".policyActivity"> <ScrollView android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" tools:ignore="MissingConstraints"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/tv_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30dp"/> <TextView android:id="@+id/tv_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20dp"/> </LinearLayout> </ScrollView> </LinearLayout>