少爺放過我吧
今天實現科技政策查詢的前端,我前端設計的頁面包括輸入框,全國,河北省,外省的按鈕,這樣方便有代表性的查詢。
package com.zhen; import android.util.Log; import android.view.View; import android.widget.*; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import com.google.gson.reflect.TypeToken; import com.zhen.adapter.PolicyListAdapter; import com.zhen.net.OkHttpUtils; import com.zhen.pojp.IP; import com.zhen.pojp.Policy; import com.google.gson.Gson; import java.util.List; public class activity_text extends AppCompatActivity { private EditText searchBox; private ImageButton searchBtn; private Button nationBtn, hebeiBtn, waishengBtn; private ListView mainLv; private PolicyListAdapter policyListAdapter; private IP ip; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_text); ip = new IP(); ip.setIp(); initView(); initEvent(); } private void initEvent() { showMain(); searchBu(); nationBu(); hebeiBu(); waishengBu(); } private void waishengBu() { waishengBtn.setOnClickListener(view -> OkHttpUtils.getInstance().doGet("http://" + ip.getIp() + ":8080/policy/getWaisheng", new CallBack() { @Override public void onSuccess(String result) { show1(result); } @Override public void onError(Exception e) { Toast.makeText(activity_text.this, "查詢不到結果!", Toast.LENGTH_SHORT).show(); } })); } private void hebeiBu() { hebeiBtn.setOnClickListener(view -> OkHttpUtils.getInstance().doGet("http://" + ip.getIp() + ":8080/policy/getHebei", new CallBack() { @Override public void onSuccess(String result) { show1(result); } @Override public void onError(Exception e) { Toast.makeText(activity_text.this, "查詢不到結果!", Toast.LENGTH_SHORT).show(); } })); } private void nationBu() { nationBtn.setOnClickListener(view -> OkHttpUtils.getInstance().doGet("http://" + ip.getIp() + ":8080/policy/getNation", new CallBack() { @Override public void onSuccess(String result) { show1(result); } @Override public void onError(Exception e) { Toast.makeText(activity_text.this, "查詢不到結果!", Toast.LENGTH_SHORT).show(); } })); } private void searchBu() { searchBtn.setOnClickListener(view -> { String searchText = searchBox.getText().toString(); if (searchText.equals("")) { Toast.makeText(activity_text.this, "請輸入搜尋內容", Toast.LENGTH_SHORT).show(); } else { OkHttpUtils.getInstance().doGet("http://" + ip.getIp() + ":8080/policy/getByName?name=" + searchText, new CallBack() { @Override public void onSuccess(String result) { show1(result); } @Override public void onError(Exception e) { Toast.makeText(activity_text.this, "查詢不到結果!", Toast.LENGTH_SHORT).show(); } }); } }); } private void showMain() { OkHttpUtils.getInstance().doGet("http://" + ip.getIp() + ":8080/policy/getAll", new CallBack() { @Override public void onSuccess(String result) { show1(result); } @Override public void onError(Exception e) { Toast.makeText(activity_text.this, "查詢不到結果!", Toast.LENGTH_SHORT).show(); } }); } public void show1(String result) { Gson gson = new Gson(); List<Policy> policyList = gson.fromJson(result, new TypeToken<List<Policy>>() { }.getType()); policyListAdapter = new PolicyListAdapter(activity_text.this, R.layout.item_policy, policyList); mainLv.setAdapter(policyListAdapter); } private void initView() { searchBox = findViewById(R.id.search_box); searchBtn = findViewById(R.id.searchBtn); nationBtn = findViewById(R.id.nationBtn); hebeiBtn = findViewById(R.id.hebeiBtn); waishengBtn = findViewById(R.id.waishengBtn); mainLv = findViewById(R.id.main_lv); } }