今天仔细想了一下,这个项目确实没有什么有技术含量的知识,只是Android的一些基础,建民老师说如果能做出点新意也行,不过我们大概也没有精力去推广,提前接触一些大赛的题目也挺好,还可以学到更多更深层次的知识,所以现在
打算用几天时间把这个app做完,我估算了一下,到下周二应该可以大体做完。
基本完成了主页,剩下一些小bug,明天修复然后把社区大体做完。
肝!
1、主界面(已完成)
2、商品展示界面(已完成)
3、商品详情界面(已完成)
4、 添加商品界面(已完成)
5、从数据库读取相关类别商品信息并传入商品展示界面(已完成)
6、从数据库读取相关商品的评论传入商品详情界面(已完成)
7、添加相关商品的评论到数据库(已完成)
8、添加商品信息到数据库(已完成)
9、关键词搜索(已完成)
10、动态加载商品
社区相关:
1、社区主界面(明日待办)
2、帖子详情,包括点赞评论回复的实现(明日待办)
3、发帖界面(明日待办)
4、将贴子信息传输至数据库(明日待办)
5、从数据库读取帖子信息并展示(明日待办)
6、从数据库读取帖子的相关评论及回复(明日待办)
今天和昨天的代码
package com.example.xiaoyi_test_2.Fragment; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; import com.alibaba.fastjson.JSONArray; import com.example.xiaoyi_test_2.Activity.AddActivity; import com.example.xiaoyi_test_2.Activity.MainActivity; import com.example.xiaoyi_test_2.Bean.ItemBean; import com.example.xiaoyi_test_2.R; import com.example.xiaoyi_test_2.Service.ItemService; import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList; import java.util.List; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.FindListener; public class Fragment_Item extends Fragment implements View.OnClickListener, ItemService.SendAll{ private FloatingActionButton btn_float; private ImageView imageView; private Fragment_ShowItem fragment_showItem; private RadioGroup rg_type; private ProgressBar loadprogress; private TextView tv_all; private boolean LogState = false; private String username = "xiaoGao"; private Button btn_book,btn_search; private EditText et_search; private ImageView head; private boolean first=true; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.layout_frag_item, container, false); initViews(view); return view; } private void initViews(View view) { //初始化商品界面 loadprogress = view.findViewById(R.id.main_show_progress); loadprogress.setVisibility(View.INVISIBLE); head = view.findViewById(R.id.item_head); head.setOnClickListener(this); tv_all = view.findViewById(R.id.main_tv_all); btn_float = view.findViewById(R.id.main_btn_float); btn_float.setOnClickListener(this); et_search = view.findViewById(R.id.mian_et_search); rg_type = view.findViewById(R.id.main_rd_type); btn_book = view.findViewById(R.id.btn_book); btn_book.setOnClickListener(this); btn_search=view.findViewById(R.id.mian_btn_search); et_search=view.findViewById(R.id.mian_et_search); btn_search.setOnClickListener(this); ItemService.getAll(this); loadprogress.setVisibility(View.VISIBLE); tv_all.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadprogress.setVisibility(View.VISIBLE); ItemService.getAll(Fragment_Item.this); // BmobQuery<ItemBean> beanBmobQuery = new BmobQuery<>(); // beanBmobQuery.findObjects(new FindListener<ItemBean>() { // @Override // public void done(List<ItemBean> list, BmobException e) { // if (e == null) { // loadprogress.setVisibility(View.INVISIBLE); // Log.d("==================", "=========="); // getActivity().getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_right_in, // R.anim.slide_left_out, // R.anim.slide_left_in, // R.anim.slide_right_out).replace(R.id.main_frag, Fragment_ShowItem.newInstance((ArrayList<ItemBean>) list)).commitAllowingStateLoss(); // } else Log.d("------query", e.getMessage()); // } // }); } }); rg_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { loadprogress.setVisibility(View.VISIBLE); ItemService.getType(Fragment_Item.this,((RadioButton) (getActivity().findViewById(rg_type.getCheckedRadioButtonId()))).getText().toString()); // BmobQuery<ItemBean> beanBmobQuery = new BmobQuery<>(); // if (((RadioButton) (getActivity().findViewById(rg_type.getCheckedRadioButtonId()))).getText().equals("书籍资料")) { // // } else { // beanBmobQuery.addWhereEqualTo("bigtype", ((RadioButton) (getActivity().findViewById(rg_type.getCheckedRadioButtonId()))).getText()); // beanBmobQuery.findObjects(new FindListener<ItemBean>() { // @Override // public void done(List<ItemBean> list, BmobException e) { // if (e == null) { // loadprogress.setVisibility(View.INVISIBLE); // getActivity().getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_right_in, // R.anim.slide_left_out, // R.anim.slide_left_in, // R.anim.slide_right_out).replace(R.id.main_frag, Fragment_ShowItem.newInstance((ArrayList<ItemBean>) list)).commitAllowingStateLoss(); // } else Log.d("------query", e.getMessage()); // } // }); // } } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.main_btn_float: { Intent intent = new Intent(getContext(), AddActivity.class); startActivityForResult(intent, 0); break; } case R.id.btn_book: { getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.main_frag, Fragment_Book.newInstance()).commitAllowingStateLoss(); break; } case R.id.item_head: { ((MainActivity) getActivity()).drawerLayout.openDrawer(Gravity.LEFT); break; } case R.id.mian_btn_search:{ if ((!et_search.getText().toString().equals(""))&&et_search.getText().toString()!=null){ ItemService.searchKey(Fragment_Item.this,et_search.getText().toString()); } else { Toast.makeText(getContext(),"请输入关键词",Toast.LENGTH_SHORT); } } } } @Override public void sendAll(JSONArray jsonArray) { final ArrayList<ItemBean> arrayList; if (jsonArray!=null) { arrayList= (ArrayList<ItemBean>) jsonArray.toJavaList(ItemBean.class); }else { arrayList=new ArrayList<>(); } getActivity().runOnUiThread(new Runnable() { @Override public void run() { loadprogress.setVisibility(View.INVISIBLE); getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.main_frag, Fragment_ShowItem.newInstance((ArrayList<ItemBean>) arrayList)).commitAllowingStateLoss(); } }); } public interface HeadClick { public void headClick(); } } package com.example.xiaoyi_test_2.Service; import android.content.Context; import android.util.Log; import android.widget.Toast; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.example.xiaoyi_test_2.Activity.ShowDetailActivity; import com.example.xiaoyi_test_2.Bean.SayToItemBean; import java.io.IOException; import java.util.List; import okhttp3.Call; import okhttp3.Callback; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public class ItemComponent { public static void saveFirstSay(final SayToItemBean sayToItemBean, final Context context){ new Thread(new Runnable() { @Override public void run() { MediaType mediaType=MediaType.parse("application/json; charset=utf-8"); Request request=new Request.Builder() .url("http://123.56.137.134/XiaoYiServer/AddItemComp") .post(RequestBody.create(mediaType, JSONObject.toJSONString(sayToItemBean))).build(); OkHttpClient okHttpClient=new OkHttpClient(); Call call=okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { // ((ShowDetailActivity)context).runOnUiThread(new Runnable() { // @Override // public void run() { // Toast.makeText(context, "+_+ 发布成功 +_+", Toast.LENGTH_SHORT).show(); // } // }); } }); } }).start(); } public static void getAllAbout(final int id, final SendAboutC sendAboutC){ new Thread(new Runnable() { @Override public void run() { MediaType mediaType=MediaType.parse("text/x-markdown; charset=utf-8"); String request_body=""+id; Request request=new Request.Builder(). url("http://123.56.137.134/XiaoYiServer/GetCompent") .post(RequestBody.create(mediaType,request_body)).build(); OkHttpClient okHttpClient=new OkHttpClient(); okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //response.body只能调一次 String body=response.body().string(); Log.d("IC-------",body); List<SayToItemBean> list=JSONObject.parseArray(body,SayToItemBean.class); sendAboutC.sendAC(list); } }); } }).start(); } public interface SendAboutC{ public void sendAC(List<SayToItemBean> list); } } package com.example.xiaoyi_test_2.Service; import android.content.Context; import android.util.Log; import android.widget.Toast; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.example.xiaoyi_test_2.Activity.AddActivity; import com.example.xiaoyi_test_2.Bean.ItemBean; import com.example.xiaoyi_test_2.R; import com.example.xiaoyi_test_2.Utils.Base36Utils; import com.example.xiaoyi_test_2.Utils.RangeUtil; import com.example.xiaoyi_test_2.Utils.SPUtils; import java.io.File; import java.io.IOException; import okhttp3.Call; import okhttp3.Callback; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public class ItemService { public static void addItem(ItemBean itemBean, final Context context, final SendAddItem sendAddItem) { String imgpath = ""; if (itemBean.getImg() != null) { String s = Base36Utils.imageToBase64(itemBean.getImg()); MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); String request_body = s; String name = (String) SPUtils.get(context, "phone", "") + RangeUtil.getRange(); imgpath += ("http://123.56.137.134/photo_XY/" + name + ".jpg|"); Request request = new Request.Builder() .url("http://123.56.137.134/XiaoYiServer/AddPhoto") .addHeader("name", name) .post(RequestBody.create(mediaType, request_body)).build(); OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { Log.d("LogAndRegister-------", "phone查询请求失败"); } @Override public void onResponse(Call call, Response response) throws IOException { //response.body只能调一次 } }); itemBean.setImg(null); } if (itemBean.getImg_2() != null) { String s = Base36Utils.imageToBase64(itemBean.getImg_2()); MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); String request_body = s; String name = (String) SPUtils.get(context, "phone", "") + RangeUtil.getRange(); imgpath += ("http://123.56.137.134/photo_XY/" + name + ".jpg|"); Request request = new Request.Builder(). url("http://123.56.137.134/XiaoYiServer/AddPhoto") .addHeader("name", name) .post(RequestBody.create(mediaType, request_body)).build(); OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { Log.d("LogAndRegister-------", "phone查询请求失败"); } @Override public void onResponse(Call call, Response response) throws IOException { //response.body只能调一次 } }); itemBean.setImg_2(null); } if (itemBean.getImg() != null) { String s = Base36Utils.imageToBase64(itemBean.getImg_3()); MediaType mediaType = MediaType.parse("text/x-markdown; charset=utf-8"); String request_body = s; String name = (String) SPUtils.get(context, "phone", "") + RangeUtil.getRange(); imgpath += ("http://123.56.137.134/photo_XY/" + name + ".jpg|"); Request request = new Request.Builder(). url("http://123.56.137.134/XiaoYiServer/AddPhoto") .addHeader("name", name) .post(RequestBody.create(mediaType, request_body)).build(); OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { Log.d("itemService-------", "存储失败!"); } @Override public void onResponse(Call call, Response response) throws IOException { //response.body只能调一次 } }); itemBean.setImg_3(null); } itemBean.setImgpath(imgpath); final boolean[] flag = {false}; OkHttpClient okHttpClient = new OkHttpClient(); MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); Request request = new Request.Builder() .url("http://123.56.137.134/XiaoYiServer/AddItem") .post(RequestBody.create(mediaType, JSON.toJSONString(itemBean))).build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { e.printStackTrace(); } @Override public void onResponse(Call call, Response response) throws IOException { String s=response.body().string(); sendAddItem.sendAddItem(s); Log.d("ItemService------",s); } }); } public static void getAll(final SendAll sendAll){ OkHttpClient okHttpClient=new OkHttpClient(); MediaType mediaType=MediaType.parse("text/x-markdown; charset=utf-8"); final Request request=new Request.Builder() .url("http://123.56.137.134/XiaoYiServer/sendItem") .post(RequestBody.create(mediaType,"1")) .build(); Call call=okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { String s=response.body().string(); Log.d("ItemService------","--+"+s); JSONArray jsonArray=JSONArray.parseArray(s); sendAll.sendAll(jsonArray); } }); } public static void searchKey(final SendAll sendAll,String key){ OkHttpClient okHttpClient=new OkHttpClient(); MediaType mediaType=MediaType.parse("ext/x-markdown; charset=utf-8"); Request request=new Request.Builder() .url("http://123.56.137.134/XiaoYiServer/SearchKey") .post(RequestBody.create(mediaType,key)) .build(); Call call=okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { String s=response.body().string(); Log.d("ItemService------","--+"+s); JSONArray jsonArray=JSONArray.parseArray(s); sendAll.sendAll(jsonArray); } }); } public static void getType(final SendAll sendAll,String key){ OkHttpClient okHttpClient=new OkHttpClient(); MediaType mediaType=MediaType.parse("ext/x-markdown; charset=utf-8"); Request request=new Request.Builder() .url("http://123.56.137.134/XiaoYiServer/GetType") .post(RequestBody.create(mediaType,key)) .build(); Call call=okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { String s=response.body().string(); Log.d("ItemService------","--+"+s); JSONArray jsonArray=JSONArray.parseArray(s); sendAll.sendAll(jsonArray); } }); } public interface SendAddItem{ public void sendAddItem(String s); } public interface SendAll{ public void sendAll(JSONArray jsonArray); } } package com.example.xiaoyi_test_2.CommentToItem; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Toast; import com.example.xiaoyi_test_2.Bean.SayToItemBean; import com.example.xiaoyi_test_2.Activity.LoginActivity; import com.example.xiaoyi_test_2.R; import com.example.xiaoyi_test_2.Activity.ShowDetailActivity; import com.example.xiaoyi_test_2.Service.ItemComponent; import com.example.xiaoyi_test_2.Utils.SPUtils; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.SaveListener; public class SayToCommentClass { private LinearLayout root; private Context context; private Button btn_send; private EditText et; private ImageView face; private SayToItemBean itemBean; private Dialog dialog; private SayToCommentClass.sendAdd sendAdd; private int posi; public SayToCommentClass(LinearLayout root, Context context, SayToItemBean itemBean, Dialog mdialog, sendAdd sendAdd, int posi) { this.root = root; this.context = context; this.itemBean = itemBean; this.dialog = mdialog; this.posi = posi; this.sendAdd = sendAdd; bindViews(root); } private void bindViews(LinearLayout root) { btn_send = root.findViewById(R.id.saytoitem_btn); et = root.findViewById(R.id.saytoitem_et); face = root.findViewById(R.id.saytoitem_face); btn_send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hintKbTwo(); if (SPUtils.get(context, "username", "111") == null) { Intent intent = new Intent(context, LoginActivity.class); ((ShowDetailActivity) context).startActivityForResult(intent, 0); Toast.makeText(context, "请先登录!", Toast.LENGTH_SHORT).show(); } else { SayToItemBean sayToItemBean = new SayToItemBean(); sayToItemBean.setItemid(itemBean.getItemid()); sayToItemBean.setUserid((Integer) SPUtils.get(context, "userid", 1)); sayToItemBean.setSaywhat(et.getText().toString()); sayToItemBean.setAbovecomment(itemBean.getId()); sayToItemBean.save(context); sendAdd.sendl(sayToItemBean, posi); } dialog.dismiss(); } }); } //隐藏键盘 private void hintKbTwo() { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive() && dialog.getCurrentFocus() != null) { if (dialog.getCurrentFocus().getWindowToken() != null) { imm.hideSoftInputFromWindow(dialog.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } } public interface sendAdd { public void sendl(SayToItemBean itemBean, int posi); } } package com.example.xiaoyi_test_2.CommentToItem; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Toast; import com.example.xiaoyi_test_2.Bean.ItemBean; import com.example.xiaoyi_test_2.Bean.SayToItemBean; import com.example.xiaoyi_test_2.Activity.LoginActivity; import com.example.xiaoyi_test_2.R; import com.example.xiaoyi_test_2.Activity.ShowDetailActivity; import com.example.xiaoyi_test_2.Utils.SPUtils; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.SaveListener; public class SayToItemClass { private LinearLayout root; private Context context; private Button btn_send; private EditText et; private ImageView face; private ItemBean itemBean; private Dialog dialog; private sendAdd sendAdd; public SayToItemClass(LinearLayout root, Context context, ItemBean itemBean, Dialog mdialog, sendAdd sendAdd) { this.root = root; this.context = context; this.itemBean = itemBean; this.dialog = mdialog; this.sendAdd = sendAdd; bindViews(root); } private void bindViews(LinearLayout root) { btn_send = root.findViewById(R.id.saytoitem_btn); et = root.findViewById(R.id.saytoitem_et); face = root.findViewById(R.id.saytoitem_face); btn_send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hintKbTwo(); if (SPUtils.get(context, "username", "111") == null) { Intent intent = new Intent(context, LoginActivity.class); ((ShowDetailActivity) context).startActivityForResult(intent, 0); Toast.makeText(context, "请先登录!", Toast.LENGTH_SHORT).show(); } else { SayToItemBean sayToItemBean = new SayToItemBean(); sayToItemBean.setUserid((Integer) SPUtils.get(context, "userid", 1)); sayToItemBean.setSaywhat(et.getText().toString()); sayToItemBean.setItemid(itemBean.getId()); sayToItemBean.save(context); sendAdd.send(sayToItemBean); } dialog.dismiss(); } }); } //隐藏键盘 private void hintKbTwo() { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive() && dialog.getCurrentFocus() != null) { if (dialog.getCurrentFocus().getWindowToken() != null) { imm.hideSoftInputFromWindow(dialog.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } } public interface sendAdd { public void send(SayToItemBean itemBean); } } package com.example.xiaoyi_test_2.CommentToItem; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Toast; import com.example.xiaoyi_test_2.Bean.SayToItemBean; import com.example.xiaoyi_test_2.Activity.LoginActivity; import com.example.xiaoyi_test_2.R; import com.example.xiaoyi_test_2.Activity.ShowDetailActivity; import com.example.xiaoyi_test_2.Utils.SPUtils; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.SaveListener; public class SayToReplyClass { private LinearLayout root; private Context context; private Button btn_send; private EditText et; private ImageView face; private SayToItemBean itemBean; private Dialog dialog; private SayToReplyClass.sendAdd sendAdd; private int posi; public SayToReplyClass(LinearLayout root, Context context, SayToItemBean itemBean, Dialog mdialog, sendAdd sendAdd, int posi) { this.root = root; this.context = context; this.itemBean = itemBean; this.dialog = mdialog; this.posi = posi; this.sendAdd = sendAdd; bindViews(root); } private void bindViews(LinearLayout root) { btn_send = root.findViewById(R.id.saytoitem_btn); et = root.findViewById(R.id.saytoitem_et); face = root.findViewById(R.id.saytoitem_face); btn_send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hintKbTwo(); if (SPUtils.get(context, "username", "111") == null) { Intent intent = new Intent(context, LoginActivity.class); ((ShowDetailActivity) context).startActivityForResult(intent, 0); Toast.makeText(context, "请先登录!", Toast.LENGTH_SHORT).show(); } else { SayToItemBean sayToItemBean = new SayToItemBean(); sayToItemBean.setUserid((Integer) SPUtils.get(context, "userid", 1)); sayToItemBean.setSaywhat(et.getText().toString()); sayToItemBean.setTouerid(itemBean.getUserid()); sayToItemBean.setItemid(itemBean.getItemid()); sayToItemBean.setAbovecomment(itemBean.getId()); sayToItemBean.save(context); sendAdd.send(sayToItemBean, posi); } dialog.dismiss(); } }); } //隐藏键盘 private void hintKbTwo() { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive() && dialog.getCurrentFocus() != null) { if (dialog.getCurrentFocus().getWindowToken() != null) { imm.hideSoftInputFromWindow(dialog.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } } public interface sendAdd { public void send(SayToItemBean itemBean, int posi); } }
package com.main.java; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONArray; import bean.ItemBean; import utils.DBUtil; @WebServlet("/SearchKey") public class SearchKey extends HttpServlet { private static final long serialVersionUID = 1L; public SearchKey() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); InputStream is=request.getInputStream(); InputStreamReader ir=new InputStreamReader(is); BufferedReader br=new BufferedReader(ir); StringBuffer sb=new StringBuffer(); String s=""; while((s=br.readLine())!=null) { sb.append(s); } br.close(); ir.close(); is.close(); String key=sb.toString(); ArrayList<ItemBean> arr=new ArrayList<>(); try { Connection con=DBUtil.lin("XiaoYi"); Statement stmt=con.createStatement(); String sql="select * from item where bigtype like '%"+key+"%' or `describe` like '%"+key+"' or type like '%"+key+"%'"; ResultSet rsst=stmt.executeQuery(sql); while(rsst.next()) { ItemBean it=new ItemBean(); it.setDescribe(rsst.getString("describe")); Statement stmt2=con.createStatement(); ResultSet rsst2=stmt2.executeQuery("select name from user where phone='"+rsst.getString("phone")+"'"); if(rsst2.next()) { it.setUsername(rsst2.getString("name")); } it.setId(rsst.getInt("id")); it.setPhone(rsst.getString("phone")); it.setMoney(rsst.getString("money")); it.setBigtype(rsst.getString("bigtype")); it.setType(rsst.getString("type")); it.setPosi(rsst.getString("posi")); it.setImgspath(rsst.getString("imgpath")); it.setDate(rsst.getDate("creat_time")); stmt2.close(); rsst2.close(); arr.add(it); } rsst.close(); stmt.close(); con.close(); System.out.println(JSONArray.toJSONString(arr)); response.setCharacterEncoding("utf-8"); response.getWriter().print(JSONArray.toJSONString(arr)); response.getWriter().close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } package com.main.java; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import utils.DBUtil; @WebServlet("/AddItemComp") public class AddItemComp extends HttpServlet { private static final long serialVersionUID = 1L; public AddItemComp() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); InputStream is=request.getInputStream(); InputStreamReader ir=new InputStreamReader(is); BufferedReader br=new BufferedReader(ir); StringBuffer sb=new StringBuffer(); String s=""; while((s=br.readLine())!=null) { sb.append(s); } br.close(); ir.close(); is.close(); JSONObject jsonObject=JSON.parseObject(sb.toString()); System.out.println(sb.toString()); try { Connection con=DBUtil.lin("XiaoYi"); Statement stmt=con.createStatement(); String sql="insert into itemcomment(userid,itemid,saywhat,abovecomment,touserid) value("+jsonObject.getIntValue("userid")+","+ jsonObject.getIntValue("itemid")+",'"+jsonObject.getString("saywhat")+"',"+jsonObject.getIntValue("abovecomment")+","+jsonObject.getIntValue("touserid")+")"; stmt.executeUpdate(sql); stmt.close(); con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } response.setCharacterEncoding("utf-8"); response.getWriter().print("true"); response.getWriter().close(); } } package com.main.java; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import bean.CompentBean; import bean.UserBean; import utils.DBUtil; @WebServlet("/GetCompent") public class GetCompent extends HttpServlet { private static final long serialVersionUID = 1L; public GetCompent() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); InputStream is=request.getInputStream(); InputStreamReader ir=new InputStreamReader(is); BufferedReader br=new BufferedReader(ir); String s=""; StringBuffer sb=new StringBuffer(); while((s=br.readLine())!=null) { sb.append(s); } System.out.println(sb.toString()); ArrayList<CompentBean> arr=new ArrayList<CompentBean>(); try { Connection con=DBUtil.lin("XiaoYi"); Statement stmt=con.createStatement(); String sql="select * from itemcomment where itemid="+Integer.parseInt(sb.toString()); ResultSet rsst=stmt.executeQuery(sql); while(rsst.next()) { CompentBean compentBean=new CompentBean(); compentBean.setAbovecomment(rsst.getInt("abovecomment")); compentBean.setUserid(rsst.getInt("userid")); compentBean.setTouserid(rsst.getInt("touserid")); compentBean.setId(rsst.getInt("id")); compentBean.setItemid(rsst.getInt("itemid")); compentBean.setSaywhat(rsst.getString("saywhat")); compentBean.setDate(rsst.getDate("creatdate")); arr.add(compentBean); } stmt.close(); con.close(); br.close(); ir.close(); is.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONArray jsonArray=JSONArray.parseArray(JSONArray.toJSONString(arr)); System.out.println(jsonArray); response.setCharacterEncoding("utf-8"); response.getWriter().write(jsonArray.toJSONString()); response.getWriter().close(); } } package com.main.java; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONArray; import bean.ItemBean; import utils.DBUtil; @WebServlet("/GetType") public class GetType extends HttpServlet { private static final long serialVersionUID = 1L; public GetType() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); InputStream is=request.getInputStream(); InputStreamReader ir=new InputStreamReader(is); BufferedReader br=new BufferedReader(ir); StringBuffer sb=new StringBuffer(); String s=""; while((s=br.readLine())!=null) { sb.append(s); } br.close(); ir.close(); is.close(); String btype=sb.toString(); ArrayList<ItemBean> arr=new ArrayList<ItemBean>(); try { Connection con=DBUtil.lin("XiaoYi"); Statement stmt=con.createStatement(); String sql="select * from item where bigtype='"+btype+"'"; ResultSet rsst=stmt.executeQuery(sql); while(rsst.next()) { ItemBean it=new ItemBean(); it.setDescribe(rsst.getString("describe")); Statement stmt2=con.createStatement(); ResultSet rsst2=stmt2.executeQuery("select name from user where phone='"+rsst.getString("phone")+"'"); if(rsst2.next()) { it.setUsername(rsst2.getString("name")); } it.setId(rsst.getInt("id")); it.setPhone(rsst.getString("phone")); it.setMoney(rsst.getString("money")); it.setBigtype(rsst.getString("bigtype")); it.setType(rsst.getString("type")); it.setPosi(rsst.getString("posi")); it.setImgspath(rsst.getString("imgpath")); it.setDate(rsst.getDate("creat_time")); stmt2.close(); rsst2.close(); arr.add(it); } rsst.close(); stmt.close(); con.close(); System.out.println(JSONArray.toJSONString(arr)); response.setCharacterEncoding("utf-8"); response.getWriter().print(JSONArray.toJSONString(arr)); response.getWriter().close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }