2024/5/28

所学时间:2小时

代码行数:400

博客园数:1篇

所学知识:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="科技政策一点通"
android:textSize="30dp"/>

</LinearLayout>


<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">

<EditText
android:id="@+id/policy"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@drawable/round_edittext_bg"
android:hint="请输入关键字">

</EditText>
<Button
android:id="@+id/key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/blue"
android:text="搜索">

</Button>

</LinearLayout>
<LinearLayout
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:id="@+id/country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:text="国家"
android:textSize="10dp"
android:textColor="@color/black"
tools:ignore="ButtonStyle" />

<Button
android:id="@+id/hebei"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:text="河北"
android:textSize="10dp"
android:textColor="@color/black"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/other_province"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:textSize="10dp"
android:text="外省"
android:textColor="@color/black"
tools:ignore="ButtonStyle" />
</LinearLayout>
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ListView
android:id="@+id/lvInaccountInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"/>
</LinearLayout>
</LinearLayout>
package com.example.policy.Frafment;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.policy.R;
import com.example.policy.sql.MySQLConnector;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class FullTextFrafment extends Fragment {
private Button country,hebei,other_province,key;
private EditText policy;
private String str_policy;

private ListView InaccountInfo;
ArrayList<String> resultList = new ArrayList<>();
private MySQLConnector mySQLConnector;
public FullTextFrafment() {
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){

return inflater.inflate(R.layout.full_text, container, false);
}
public void onViewCreated(@NonNull View view, @NonNull Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
policy=view.findViewById(R.id.policy);
country=view.findViewById(R.id.country);
hebei=view.findViewById(R.id.hebei);
other_province=view.findViewById(R.id.other_province);
key=view.findViewById(R.id.key);
InaccountInfo=(ListView)getView().findViewById(R.id.lvInaccountInfo);
key.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try {
resultList.clear();
Connection connection=mySQLConnector.getConn();
str_policy=policy.getText().toString();
String sql="select id,name from policy where name like '%"+str_policy+"%' ";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String nametext=resultSet.getString("name");
resultList.add(nametext);
}
} catch (Exception e) {

}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String[] fulltext=new String[resultList.size()];
for (int i = 0; i <resultList.size() ; i++) {
fulltext[i]=resultList.get(i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,fulltext );
InaccountInfo.setAdapter(adapter);
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {

Connection connection=mySQLConnector.getConn();
String sql="select text from policy where name like '%"+str_policy+"%' ";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("text");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();

}
});
}
});

}
}).start();
}
});
country.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try {
resultList.clear();
Connection connection=mySQLConnector.getConn();
String sql="select id,name from policy where policy.range= '全国(000000 QG)'";
Log.e("11111111111111111","select id,name,text from policy where policy.range= '全国(000000 QG)'");
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String nametext=resultSet.getString("name");
resultList.add(nametext);
}
} catch (Exception e) {

}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String[] fulltext=new String[resultList.size()];
for (int i = 0; i <resultList.size() ; i++) {
fulltext[i]=resultList.get(i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,fulltext );
InaccountInfo.setAdapter(adapter);
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {

Connection connection=mySQLConnector.getConn();
String sql="select text from policy where policy.range= '全国(000000 QG)'";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("text");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();

}
});
}
});

}
}).start();
}
});
hebei.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try {
resultList.clear();
Connection connection=mySQLConnector.getConn();
String sql = "select id,name from policy where policy.range= '河北省(130000 HE)'";
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()) {
String nametext = resultSet.getString("name");
resultList.add(nametext);
}
} catch (Exception e) {

}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {

String[] fulltext = new String[resultList.size()];
for (int i = 0; i < resultList.size(); i++) {
fulltext[i] = resultList.get(i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, fulltext);
InaccountInfo.setAdapter(adapter);
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {

Connection connection=mySQLConnector.getConn();
String sql="select text from policy where policy.range= '河北省(130000 HE)'";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("text");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();

}
});
}
});
}
}).start();
}
});
other_province.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try {
resultList.clear();
Connection connection= mySQLConnector.getConn();
String sql="select id,name from policy where policy.range!= '河北省(130000 HE)'and policy.range!='全国(000000 QG)'";
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()) {
String nametext = resultSet.getString("name");
resultList.add(nametext);
}
} catch (Exception e) {

}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String[] fulltext = new String[resultList.size()];
for (int i = 0; i < resultList.size(); i++) {
fulltext[i] = resultList.get(i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, fulltext);
InaccountInfo.setAdapter(adapter);
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {

Connection connection=mySQLConnector.getConn();
String sql="select text from policy where policy.range!= '河北省(130000 HE)'and policy.range!='全国(000000 QG)'";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("text");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();

}
});
}
});
}
}).start();
}
});

}
private void showBlankDialog(String temp){
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("文本内容")
.setMessage(temp)
.setPositiveButton("关闭", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
}
posted @ 2024-05-28 22:51  为20岁努力  阅读(1)  评论(0编辑  收藏  举报