接口MVP原生登录注册+搜索+recycleView切换展示
2018-01-07 20:27
591 查看
接口MVP原生登录注册+搜索+recycleView切换展示
依赖
compile 'com.squareup.okhttp3:okhttp:3.9.1' compile 'com.google.code.gson:gson:2.8.2' compile 'com.android.support:design:26.+' compile 'com.jcodecraeer:xrecyclerview:1.5.2' compile 'com.github.bumptech.glide:glide:3.7.0'
权限
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
model包
LoginModel
import android.os.Handler; import com.bwie.week2test.Contents; import com.bwie.week2test.presenter.ILoginPresenter; import java.io.IOException; import java.util.HashMap; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class LoginModel implements ILoginModel{ private static Handler handler=new Handler(); @Override public void login(String mobile, String password, final ILo 4000 ginPresenter iLoginPresenter) { String url=Contents.LOGIN+"?mobile="+mobile+"&password="+password; OkHttpClient okHttpClient=new OkHttpClient(); Request request=new Request.Builder() .get() .url(url) .build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { iLoginPresenter.onFailed(e.getMessage()); } }); } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ final String result = response.body().string(); handler.post(new Runnable() { @Override public void run() { iLoginPresenter.onSuccess(result); } }); } } }); } }
ILoginModel接口
public interface ILoginModel { void login(String mobile, String password, ILoginPresenter iLoginPresenter); }
RegisterModel
public class RegisterModel implements IRegisterModel { private static Handler handler=new Handler(); @Override public void register(String mobile, String password, final IRegisterPresenter iRegisterPresenter) { String url= Contents.REGISTER+"?mobile="+mobile+"&password="+password; OkHttpClient okHttpClient=new OkHttpClient(); Request request=new Request.Builder() .get() .url(url) .build(); Call call = okHttpClient.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { iRegisterPresenter.onFailed(e.getMessage()); } }); } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()){ final String result = response.body().string(); handler.post(new Runnable() { @Override public void run() { iRegisterPresenter.onSuccess(result); } }); } } }); } }
接口IRegisterModel
public interface IRegisterModel { void register(String mobile, String password, IRegisterPresenter iRegisterPresenter); }
presenter包
ILoginPresenter
public interface ILoginPresenter { void login(String mobile,String password); void onFailed(String msg); void onSuccess(Object o); void onDestory(); }
LoginPresenter
public class LoginPresenter implements ILoginPresenter { private ILoginView iLoginView; private final LoginModel loginModel; public LoginPresenter(ILoginView iLoginView) { this.iLoginView = iLoginView; loginModel = new LoginModel(); } @Override public void login(String mobile, String password) { loginModel.login(mobile,password,this); } @Override public void onFailed(String msg) { if(null==iLoginView){ return; } iLoginView.onFailed(msg); } @Override public void onSuccess(Object o) { if(null==iLoginView){ return; } Gson gson=new Gson(); LoginBean loginBean = gson.fromJson(o.toString(), LoginBean.class); String code = loginBean.getCode(); if("0".equals(code)){ iLoginView.onSuccess(loginBean.getMsg()); }else{ iLoginView.onFailed(loginBean.getMsg()); } } @Override public void onDestory() { if(null!=iLoginView){ iLoginView=null; } } }
接口IRegisterPresenter
public interface IRegisterPresenter { void register(String mobile,String password); void onFailed(String msg); void onSuccess(Object o); void onDestory(); }
RegisterPresenter
public class RegisterPresenter implements IRegisterPresenter{ private IRegisterView iRegisterView; private final RegisterModel registerModel; public RegisterPresenter(IRegisterView iRegisterView) { this.iRegisterView = iRegisterView; registerModel = new RegisterModel(); } @Override public void register(String mobile, String password) { registerModel.register(mobile,password,this); } @Override public void onFailed(String msg) { if(null==iRegisterView){ return; } iRegisterView.onFailed(msg); } @Override public void onSuccess(Object o) { if(null==iRegisterView){ return; } Gson gson=new Gson(); RegisterBean registerBean = gson.fromJson(o.toString(), RegisterBean.class); String code = registerBean.getCode(); if("0".equals(code)){ iRegisterView.onSuccess(registerBean.getMsg()); }else{ iRegisterView.onFailed(registerBean.getMsg()); } } @Override public void onDestory() { if(null!=iRegisterView){ iRegisterView=null; } } }
view包
接口ILoginView
public interface ILoginView { void onFailed(String msg); void onSuccess(Object o); }
LoginActivity
public class LoginActivity extends AppCompatActivity implements ILoginView{ private LoginPresenter loginPresenter; private EditText tel; private EditText pwd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); tel = (EditText) findViewById(R.id.mobile); pwd = (EditText) findViewById(R.id.password); loginPresenter = new LoginPresenter(this); } public void btnLogin(View view){ String mobile = tel.getText().toString(); String password = pwd.getText().toString(); loginPresenter.login(mobile,password); } public void btnRegister(View view){ Intent intent=new Intent(this,RegisterActivity.class); startActivity(intent); } @Override public void onFailed(String msg) { Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); if("天呢!用户不存在".equals(msg)){ Intent intent=new Intent(this,RegisterActivity.class); startActivity(intent); } } @Override public void onSuccess(Object o) { Toast.makeText(this, o.toString(), Toast.LENGTH_SHORT).show(); Intent intent=new Intent(this,SearchActivity.class); startActivity(intent); finish(); } @Override protected void onDestroy() { super.onDestroy(); loginPresenter.onDestory(); } }
接口IRegisterView
public interface IRegisterView { void onFailed(String msg); void onSuccess(Object o); }
RegisterActivity
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.Toast; import com.bwie.week2test.R; import com.bwie.week2test.presenter.RegisterPresenter; public class RegisterActivity extends AppCompatActivity implements IRegisterView{ private static RegisterPresenter registerPresenter; private EditText regTel; private EditText regPwd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); regTel = (EditText) findViewById(R.id.regTel); regPwd = (EditText) findViewById(R.id.regPwd); registerPresenter=new RegisterPresenter(this); } public void regNow(View view){ String mobile = regTel.getText().toString(); String password = regPwd.getText().toString(); registerPresenter.register(mobile,password); } //返回按钮 public void back(View view){ finish(); } @Override public void onFailed(String msg) { Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); } @Override public void onSuccess(Object o) { Toast.makeText(this, o.toString(), Toast.LENGTH_SHORT).show(); Intent intent=new Intent(this,LoginActivity.class); startActivity(intent); finish(); } @Override protected void onDestroy() { super.onDestroy(); registerPresenter.onDestory(); } }
SearchActivity
public class SearchActivity extends AppCompatActivity implements View.OnClickListener{ private ImageView mIvKindBack; /** * 请输入查找 */ private EditText mTextView; /** * 搜索 */ private TextView mSearchTxt; private RecyclerView mRvyHot; private ListView mRcyHistory; /** * 清空历史搜索 */ private Button mClearBtn; private SQLiteDatabase db; private String name; private DataBaseBean dataBaseBean; private List<DataBaseBean> dataList = new ArrayList<>(); private HisetroyAdapter adapter; private List<String> goodslist = new ArrayList<>(); private String searchName; private List<String> stringList = new ArrayList<String>(){ { add("应急启动电源"); add("餐桌"); add("粽子散装"); add("智能手表"); add("摩托车挂饰"); add("三只松鼠"); add("华为"); add("金士顿U盘"); add("苹果X"); add("三星耳机"); add("锤子手机"); add("伊利牛奶"); add("苹果笔记本"); add("按摩椅"); add("六个核桃"); add("公牛插座"); add("跑步机"); add("真皮钱包"); add("海澜之家"); add("阿玛尼"); add("阿迪达斯"); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); initView(); DatabaseHelper helper = new DatabaseHelper(this); db = helper.getWritableDatabase(); adapter = new HisetroyAdapter(this,goodslist); HotAdapter hotAdapter = new HotAdapter(this , stringList); LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); mRvyHot.setLayoutManager(manager); mRvyHot.setAdapter(hotAdapter); } private void initView() { mIvKindBack = (ImageView) findViewById(R.id.iv_kind_back); mTextView = (EditText) findViewById(R.id.textView); mSearchTxt = (TextView) findViewById(R.id.search_txt); mRvyHot = (RecyclerView) findViewById(R.id.rvy_hot); mRcyHistory = (ListView) findViewById(R.id.rcy_history); mClearBtn = (Button) findViewById(R.id.clear_btn); mClearBtn.setOnClickListener(this); mSearchTxt.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.clear_btn: String deleSql="delete from person"; db.execSQL(deleSql); goodslist.clear(); adapter.notifyDataSetChanged(); break; case R.id.search_txt: name = mTextView.getText().toString().trim(); db.execSQL("insert into person(name) values(?)",new Object[]{name}); mTextView.setText(""); Intent intent = new Intent(SearchActivity.this,GoodsActivity.class); intent.putExtra("data",name); startActivity(intent); break; } } @Override protected void onResume() { super.onResume(); Log.e("zxz", "我又来了 " ); Cursor cursor = db.rawQuery("select *from person", null); while (cursor.moveToNext()) { //获取第一列的值,第一列的索引从0开始 int id = cursor.getInt(0); //获取第二列的值 searchName = cursor.getString(1); Log.e("zxz", "我是shujuk:"+name + id ); } goodslist.add(searchName); mRcyHistory.setAdapter(adapter); adapter.notifyDataSetChanged(); } }
Utils包
GsonUtils
public class GsonUtils { private static Gson instance; private GsonUtils() { } public static Gson getInstance() { if (instance == null) { instance = new Gson(); } return instance; } }
SearchUtils
public class SearchUtils { private static volatile SearchUtils instance; private SearchUtils(){ } private Handler handler = new Handler(); public static SearchUtils getInstance(){ if(instance==null){ synchronized (SearchUtils.class){ if(null==instance){ instance= new SearchUtils(); } } } return instance; } public void post(String url, Map<String,String> map , final SearchCallback callBack, final Class cls){ OkHttpClient client = new OkHttpClient .Builder() .addInterceptor(new MyInterceptor()) .build(); FormBody.Builder builder = new FormBody.Builder(); for (Map.Entry<String, String> entry : map.entrySet()) { builder.add(entry.getKey(), entry.getValue()); } FormBody body = builder.build(); final Request request = new Request.Builder() .url(url) .post(body) .build(); Call call = client.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { callBack.onFailed(e); } }); } @Override public void onResponse(final Call call, Response response) throws IOException { final String data = response.body().string().trim(); handler.post(new Runnable() { @Override public void run() { if(data!=null){ Object o = GsonUtils.getInstance().fromJson(data, SearchBean.class); if(o!=null){ callBack.onSuccess(o); } } } }); } }); } }
adapter包
HisetroyAdapter
public class HisetroyAdapter extends BaseAdapter { private Context context; private List<String> list; public HisetroyAdapter(Context context, List<String> list) { this.context=context; this.list=list; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int i) { return list.get(i); } @Override public long getItemId(int i) { return i; } @Override public View getView(int i, View view, ViewGroup viewGroup) { ViewHolder holder = null; if(view==null){ holder = new ViewHolder(); view = View.inflate(context, R.layout.history_layout,null); holder.historyName = view.findViewById(R.id.history_name); view.setTag(holder); }else{ holder = (ViewHolder) view.getTag(); } if(list!=null){ holder.historyName.setText(list.get(i)); } return view; } class ViewHolder{ TextView historyName; } }
HotAdapter
public class HotAdapter extends RecyclerView.Adapter<HotAdapter.ViewHolder> { private Context con; private List<String> list; private int i ; public HotAdapter(Context con, List<String> list) { this.con = con; this.list = list; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = View.inflate(con, R.layout.item, null); ViewHolder holder = new ViewHolder(v); return holder; } @Override public void onBindViewHolder(ViewHolder holder, final int position) { holder.tv_name.setText(list.get(position)); } @Override public int getItemCount() { return list.size(); } class ViewHolder extends XRecyclerView.ViewHolder{ private TextView tv_name; public ViewHolder(View itemView) { super(itemView); tv_name = itemView.findViewById(R.id.tv_name); } } }
SearchAdapter
public class SearchAdapter extends XRecyclerView.Adapter<SearchAdapter.ViewHolder> { private Context con; private List<SearchBean.DataBean> list; private int i ; public SearchAdapter(Context con, List<SearchBean.DataBean> list,int i) { this.con = con; this.list = list; this.i=i; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = View.inflate(con, R.layout.sublist_item, null); // ViewHolder holder = new ViewHolder(view); // // return holder; if (i==1){ View v = View.inflate(con, R.layout.sublist_item, null); ViewHolder holder = new ViewHolder(v); return holder; }else if (i==2){ View v = View.inflate(con, R.layout.sublist_item2, null); ViewHolder holder = new ViewHolder(v); return holder; } return null; } @Override public void onBindViewHolder(ViewHolder holder, final int position) { holder.tvTitle.setText(list.get(position).getTitle()); holder.price.setText("¥"+list.get(position).getPrice()); // holder.num.setText("销量:"+list.get(position).getSalenum()); String images = list.get(position).getImages(); String[] split = images.split("\\|"); Glide.with(con).load(split[0]).into(holder.img); int pid = list.get(position).getPid(); // holder.itemView.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Intent intent = new Intent(con, DetailActivity.class); // intent.putExtra("pid",list.get(position).getPid()+""); // con.startActivity(intent); // } // }); } @Override public int getItemCount() { return list.size(); } class ViewHolder extends XRecyclerView.ViewHolder{ private TextView tvTitle; private TextView price; private ImageView img; private TextView num; public ViewHolder(View itemView) { super(itemView); tvTitle = itemView.findViewById(R.id.sublist_title); price = itemView.findViewById(R.id.sublist_price); num = itemView.findViewById(R.id.sublist_num); img = itemView.findViewById(R.id.sublist_img); } } }
callback
接口SearchCallback
public interface SearchCallback { void onSuccess(Object o); void onFailed(Exception e); }
接口SearchIView
public interface SearchIView { void onSuccess(List<SearchBean.DataBean> data); }
bean包
DataBaseBean
public class DataBaseBean { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
LoginBean
public class LoginBean { /** * msg : 登录成功 * code : 0 * data : {"age":null,"appkey":"ac8ba969f32989c3","appsecret":"28D322D8CD6B2CB19066BC2FA46BE523","createtime":"2018-01-06T11:11:26","email":null,"fans":null,"follow":null,"gender":null,"icon":"https://www.zhaoapi.cn/images/15135575877781513557587554.png","latitude":null,"longitude":null,"mobile":"15011445154","money":null,"nickname":null,"password":"8F669074CAF5513351A2DE5CC22AC04C","praiseNum":null,"token":"20B1C03FC676062B3B866280A24B0A40","uid":4861,"userId":null,"username":"15011445154"} */ private String msg; private String code; private DataBean data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public DataBean getData() { return data; } public void setData(DataBean data) { this.data = data; } public static class DataBean { /** * age : null * appkey : ac8ba969f32989c3 * appsecret : 28D322D8CD6B2CB19066BC2FA46BE523 * createtime : 2018-01-06T11:11:26 * email : null * fans : null * follow : null * gender : null * icon : https://www.zhaoapi.cn/images/15135575877781513557587554.png * latitude : null * longitude : null * mobile : 15011445154 * money : null * nickname : null * password : 8F669074CAF5513351A2DE5CC22AC04C * praiseNum : null * token : 20B1C03FC676062B3B866280A24B0A40 * uid : 4861 * userId : null * username : 15011445154 */ private Object age; private String appkey; private String appsecret; private String createtime; private Object email; private Object fans; private Object follow; private Object gender; private String icon; private Object latitude; private Object longitude; private String mobile; private Object money; private Object nickname; private String password; private Object praiseNum; private String token; private int uid; private Object userId; private String username; public Object getAge() { return age; } public void setAge(Object age) { this.age = age; } public String getAppkey() { return appkey; } public void setAppkey(String appkey) { this.appkey = appkey; } public String getAppsecret() { return appsecret; } public void setAppsecret(String appsecret) { this.appsecret = appsecret; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public Object getEmail() { return email; } public void setEmail(Object email) { this.email = email; } public Object getFans() { return fans; } public void setFans(Object fans) { this.fans = fans; } public Object getFollow() { return follow; } public void setFollow(Object follow) { this.follow = follow; } public Object getGender() { return gender; } public void setGender(Object gender) { this.gender = gender; } public String getIcon() { return icon; } public void setIcon(String icon) { this.icon = icon; } public Object getLatitude() { return latitude; } public void setLatitude(Object latitude) { this.latitude = latitude; } public Object getLongitude() { return longitude; } public void setLongitude(Object longitude) { this.longitude = longitude; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public Object getMoney() { return money; } public void setMoney(Object money) { this.money = money; } public Object getNickname() { return nickname; } public void setNickname(Object nickname) { this.nickname = nickname; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Object getPraiseNum() { return praiseNum; } public void setPraiseNum(Object praiseNum) { this.praiseNum = praiseNum; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } public Object getUserId() { return userId; } public void setUserId(Object userId) { this.userId = userId; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } }
RegisterBean
public class RegisterBean { /** * msg : 注册成功 * code : 0 */ private String msg; private String code; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
SearchBean
public class SearchBean { /** * msg : 查询成功 * code : 0 * data : [{"bargainPrice":11800,"createtime":"2017-10-10T17:33:37","detailUrl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg","itemtype":0,"pid":57,"price":5199,"pscid":40,"salenum":4343,"sellerid":1,"subhead":"【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统","title":"小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银\r\n"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","itemtype":1,"pid":58,"price":6399,"pscid":40,"salenum":545,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"},{"bargainPrice":5599,"createtime":"2017-10-10T17:30:32","detailUrl":"https://item.m.jd.com/product/4824715.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n12/jfs/t7768/184/1153704394/148460/f42e1432/599a930fN8a85626b.jpg!q70.jpg","itemtype":0,"pid":59,"price":5599,"pscid":40,"salenum":675,"sellerid":3,"subhead":"游戏本选择4G独显,拒绝掉帧】升级版IPS全高清防眩光显示屏,WASD方向键颜色加持,三大出风口立体散热!","title":"戴尔DELL灵越游匣15PR-6648B GTX1050 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 128GSSD+1T 4G独显 IPS)黑"},{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":2,"pid":60,"price":13888,"pscid":40,"salenum":466,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":61,"price":14999,"pscid":40,"salenum":5535,"sellerid":5,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":0,"pid":62,"price":15999,"pscid":40,"salenum":43,"sellerid":6,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":63,"price":10000,"pscid":40,"salenum":3232,"sellerid":7,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-03T23:43:53","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":0,"pid":64,"price":11000,"pscid":40,"salenum":0,"sellerid":8,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":2,"pid":65,"price":12000,"pscid":40,"salenum":868,"sellerid":9,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":66,"price":13000,"pscid":40,"salenum":7676,"sellerid":10,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}] * page : 1 */ private String msg; private String code; private String page; private List<DataBean> data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getPage() { return page; } public void setPage(String page) { this.page = page; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * bargainPrice : 11800 * createtime : 2017-10-10T17:33:37 * detailUrl : https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends * images : https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg * itemtype : 0 * pid : 57 * price : 5199 * pscid : 40 * salenum : 4343 * sellerid : 1 * subhead : 【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统 * title : 小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银 */ private double bargainPrice; private String createtime; private String detailUrl; private String images; private int itemtype; private int pid; private double price; private int pscid; private int salenum; private int sellerid; private String subhead; private String title; public double getBargainPrice() { return bargainPrice; } public void setBargainPrice(double bargainPrice) { this.bargainPrice = bargainPrice; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public String getDetailUrl() { return detailUrl; } public void setDetailUrl(String detailUrl) { this.detailUrl = detailUrl; } public String getImages() { return images; } public void setImages(String images) { this.images = images; } public int getItemtype() { return itemtype; } public void setItemtype(int itemtype) { this.itemtype = itemtype; } public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getPscid() { return pscid; } public void setPscid(int pscid) { this.pscid = pscid; } public int getSalenum() { return salenum; } public void setSalenum(int salenum) { this.salenum = salenum; } public int getSellerid() { return sellerid; } public void setSellerid(int sellerid) { this.sellerid = sellerid; } public String getSubhead() { return subhead; } public void setSubhead(String subhead) { this.subhead = subhead; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } }
主包
Contents
public class Contents { public static final String HOST_NAME="http://120.27.23.105"; public static final String LOGIN=HOST_NAME+"/user/login"; public static final String REGISTER=HOST_NAME+"/user/reg"; }
DatabaseHelper
public class DatabaseHelper extends SQLiteOpenHelper { //类没有实例化,是不能用作父类构造器的参数,必须声明为静态 private static final String name = "count"; //数据库名称 private static final int version = 1; //数据库版本 public DatabaseHelper(Context context) { //第三个参数CursorFactory指定在执行查询时获得一个游标实例的工厂类,设置为null,代表使用系统默认的工厂类 super(context, name, null, version); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE person ( id integer primary key autoincrement, name varchar(20) )"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }
GoodsActivity
public class GoodsActivity extends AppCompatActivity implements SearchIView, XRecyclerView.LoadingListener, View.OnClickListener { private static final String TAG = "GoodsActivity"; private int page = 1; private String searchName; private List<SearchBean.DataBean> data = new ArrayList<>(); private SearchAdapter adapter; private XRecyclerView mRcvKind; private boolean isFresh = true; private boolean flag = true; private ImageView mIvKindBack; private ImageView mIvKindType; private LinearLayout mLlHead; private LinearLayout mLlNestToolBar; private LinearLayout mLlKindScro; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_goods); initView(); Intent intent = getIntent(); searchName = intent.getStringExtra("data"); adapter = new SearchAdapter(this, data,1); LinearLayoutManager manager = new LinearLayoutManager(this); mRcvKind.setLayoutManager(manager); mRcvKind.setLoadingMoreEnabled(true); mRcvKind.setLoadingListener(this); mRcvKind.setAdapter(adapter); loadData(searchName, page); } private void loadData(String searchName, int page) { SearchPresenter presenter = new SearchPresenter(); presenter.attach(this); presenter.getNews(searchName, page); } @Override public void onSuccess(List<SearchBean.DataBean> newslist) { if (isFresh) { mRcvKind.refreshComplete(); } else { mRcvKind.loadMoreComplete(); } if (newslist != null) { if (isFresh) { data.clear(); } data.addAll(newslist); adapter.notifyDataSetChanged(); } if (page == 3) { Toast.makeText(this, "没有更多数据啦!", Toast.LENGTH_LONG).show(); mRcvKind.loadMoreComplete(); } } private void initView() { mRcvKind = (XRecyclerView) findViewById(R.id.rcv_kind); mIvKindBack = (ImageView) findViewById(R.id.iv_kind_back); mIvKindBack.setOnClickListener(this); mIvKindType = (ImageView) findViewById(R.id.iv_kind_type); mIvKindType.setOnClickListener(this); mLlHead = (LinearLayout) findViewById(R.id.ll_head); mLlNestToolBar = (LinearLayout) findViewById(R.id.ll_nest_toolBar); mRcvKind.setOnClickListener(this); mLlKindScro = (LinearLayout) findViewById(R.id.ll_kind_scro); mIvKindType.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (flag){ adapter.notifyDataSetChanged(); adapter = new SearchAdapter(GoodsActivity.this, data,2); mIvKindType.setImageDrawable(getResources().getDrawable(R.mipmap.liebiao)); GridLayoutManager manager = new GridLayoutManager(GoodsActivity.this, 2); mRcvKind.setLayoutManager(manager); mRcvKind.setAdapter(adapter); flag = false; }else { adapter.notifyDataSetChanged(); adapter = new SearchAdapter(GoodsActivity.this, data,1); mIvKindType.setImageDrawable(getResources().getDrawable(R.mipmap.kind_grid)); LinearLayoutManager manager = new LinearLayoutManager(GoodsActivity.this); mRcvKind.setLayoutManager(manager); mRcvKind.setAdapter(adapter); flag = true; } } }); } @Override public void onRefresh() { isFresh = true; page = 1; loadData(searchName, page); } @Override public void onLoadMore() { isFresh = false; if (page != 3) { page++; loadData(searchName, page); } } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.iv_kind_back: finish(); break; case R.id.rcv_kind: break; } } }
MyInterceptor
public class MyInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request original = chain.request(); HttpUrl url=original.url().newBuilder() .addQueryParameter("source","android") .build(); //添加请求头 Request request = original.newBuilder() .url(url) .build(); return chain.proceed(request); } }
SearchPresenter
public class SearchPresenter { private SearchIView iv; public void attach(SearchIView iv){ this.iv=iv; } public void detach(){ if(iv!=null){ iv=null; } } public void getNews(String keywords,int page){ Map<String, String> map = new HashMap<>(); map.put("keywords",keywords); map.put("page",page+""); SearchUtils.getInstance().post("http://120.27.23.105/product/searchProducts", map, new SearchCallback() { @Override public void onSuccess( Object o) { SearchBean bean = (SearchBean) o; if (bean != null){ List<SearchBean.DataBean> data = bean.getData(); if(data!=null){ iv.onSuccess(data); } } } @Override public void onFailed( Exception e) { } }, SearchBean.class); } public void detachView(){ if (iv!=null){ iv = null; } } }
布局
activity_goods.xml
<?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:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwie.week2test.GoodsActivity"> <LinearLayout android:id="@+id/ll_kind_scro" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:fitsSystemWindows="true" android:id="@+id/ll_nest_toolBar" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/ll_head" android:layout_alignParentTop="true" android:gravity="center_vertical" android:layout_width="match_parent" android:layout_height="50dp"> <LinearLayout android:padding="5dp" android:id="@+id/ll_sao" android:gravity="center" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="50dp"> <ImageView android:id="@+id/iv_kind_back" android:layout_width="30dp" android:layout_height="30dp" android:src="@mipmap/leftjiantou" /> </LinearLayout> <LinearLayout android:id="@+id/ll_search" android:padding="5dp" android:background="@drawable/search_bg_select" android:layout_weight="1" android:layout_width="0dp" android:gravity="center_vertical" android:layout_height="30dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/search_icon2" /> <TextView android:layout_weight="1" android:padding="2dp" android:textColor="@color/search_tv" android:layout_width="0dp" android:textSize="@dimen/search_tv" android:layout_height="wrap_content" android:text="11.11品牌榜" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/root" /> </LinearLayout> <LinearLayout android:padding="5dp" android:id="@+id/ll_msg" android:gravity="center" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="50dp"> <ImageView android:id="@+id/iv_kind_type" android:layout_width="30dp" android:layout_height="30dp" android:src="@mipmap/kind_grid" /> </LinearLayout> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#ccc"></View> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#ccc"></View> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#ccc"></View> <com.jcodecraeer.xrecyclerview.XRecyclerView android:id="@+id/rcv_kind" android:layout_width="match_parent" android:layout_height="match_parent"></com.jcodecraeer.xrecyclerview.XRecyclerView> </LinearLayout> </LinearLayout> </LinearLayout>
activity_login.xml
<?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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.bwie.week2test.view.LoginActivity"> <TextView android:text="登录" android:padding="20dp" android:textSize="26sp" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <View android:background="#000" android:visibility="visible" android:layout_height="1dp" android:layout_width="match_parent"></View> <EditText android:id="@+id/mobile" android:hint="请输入手机号" android:layout_marginTop="28dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/password" android:hint="请输入密码" android:layout_marginTop="28dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:text="登录" android:id="@+id/btnLogin" android:onClick="btnLogin" android:background="#1E90FF" android:layout_marginLeft="78dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="78dp" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="54dp" /> <Button android:text="注册" android:background="#1E90FF" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginRight="83dp" android:layout_marginEnd="83dp" android:layout_alignTop="@+id/btnLogin" android:onClick="btnRegister" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> </RelativeLayout> </LinearLayout>
activity_register.xml
<?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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.bwie.week2test.view.RegisterActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:background="@drawable/back" android:padding="20dp" android:onClick="back" android:textSize="40sp" android:layout_width="28dp" android:layout_height="28dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true"/> <TextView android:text="注册" android:padding="20dp" android:textSize="26sp" android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <View android:background="#000" android:visibility="visible" android:layout_height="1dp" android:layout_below="@+id/text" android:layout_width="match_parent"></View> </RelativeLayout> <EditText android:id="@+id/regTel" android:hint="请输入手机号" android:layout_marginTop="28dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/regPwd" android:hint="请输入密码" android:layout_marginTop="28dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:text="立即注册" android:onClick="regNow" android:background="#1E90FF" android:layout_marginTop="28dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"/> </LinearLayout>
activity_search.xml
<?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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.bwie.week2test.view.SearchActivity"> <include layout="@layout/serach_layout" /> <TextView android:background="@color/search_bg_select" android:layout_width="match_parent" android:layout_height="1dp" /> <LinearLayout android:padding="5dp" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="热搜" android:textColor="@color/tab_kind_normal" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <android.support.v7.widget.RecyclerView android:id="@+id/rvy_hot" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView> </LinearLayout> <LinearLayout android:orientation="vertical" android:padding="5dp" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="历史搜索" android:textColor="@color/tab_kind_normal" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android:id="@+id/rcy_history" android:layout_width="match_parent" android:layout_height="wrap_content"> </ListView> <Button android:id="@+id/clear_btn" android:text="清空历史搜索" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
history_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/history_name" android:padding="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv_name" android:layout_margin="10dp" android:textColor="#000" android:background="@drawable/textview_style" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
serach_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <LinearLayout android:id="@+id/ll_head" android:layout_width="match_parent" android:layout_height="50dp" android:background="#fff" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:id="@+id/iv_kind_back" android:layout_width="30dp" android:layout_marginLeft="10dp" android:layout_height="30dp" android:src="@mipmap/leftjiantou" /> <LinearLayout android:id="@+id/ll_search" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/search_bg_select" android:layout_marginRight="10dp" android:gravity="center_vertical" android:orientation="horizontal" android:padding="5dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/search_icon2" /> <EditText android:id="@+id/textView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@null" android:hint="请输入查找" android:padding="2dp" android:textColor="@color/search_tv" android:textSize="@dimen/search_tv" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/root" /> </LinearLayout> <LinearLayout android:id="@+id/ll_msg" android:layout_width="wrap_content" android:layout_height="50dp" android:gravity="center" android:padding="5dp"> <TextView android:layout_marginRight="10dp" android:id="@+id/search_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" /> </LinearLayout> </LinearLayout> </LinearLayout>
sublist_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <ImageView android:id="@+id/sublist_img" android:layout_width="100dp" android:layout_height="100dp" android:padding="10dp" android:src="@mipmap/ic_launcher" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:gravity="center_vertical" android:orientation="vertical" android:padding="10dp"> <TextView android:id="@+id/sublist_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按时打算打算打算打算的" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="10dp" android:orientation="horizontal"> <TextView android:id="@+id/sublist_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#f00" android:text="188元" /> <TextView android:id="@+id/sublist_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="20dp" android:text="10个" /> </RelativeLayout> </LinearLayout> </LinearLayout>
sublist_item2.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:gravity="center_vertical" android:orientation="vertical" android:padding="10dp"> <ImageView android:id="@+id/sublist_img" android:layout_width="100dp" android:layout_height="100dp" android:padding="10dp" android:src="@mipmap/ic_launcher" /> <TextView android:id="@+id/sublist_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按时打算打算打算打算的" /> <TextView android:id="@+id/sublist_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="188元" android:textColor="#f00" /> </LinearLayout> </LinearLayout>
drawable包
search_bg_select.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="@color/search_bg_select"></solid> <corners android:radius="50dp"></corners> </shape>
textview_style.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#DDDDDD" /> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="5dp" android:right="10dp" android:bottom="5dp" /> </shape>
values包
colors.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="search_bg_select">#ddd</color> <color name="search_tv">#fff</color> <color name="tab_kind_normal">#000</color> </resources>
dimens.xml
<resources> <dimen name="fab_margin">16dp</dimen> <dimen name="search_tv">12sp</dimen> </resources>
相关文章推荐
- MVP登录+recyclerview列表展示(带刷新效果)
- ViewPager实现页面切换 (包含App第一次登录时候的欢迎界面的展示)
- Android程序:实现导航滑动切换展示效果(ViewPager)
- MVP登录、注册、搜索展示案例
- MvP请求接口,进行客户端登录
- 接口做登录注册搜索展示
- MVP注册登录+OkHttp网络请求+展示数据
- MVp+RXJava+Retrofit+RecyclerView展示首页和详情页
- 使用Okhttp框架访问接口数据,通过RecyclerView进行数据展示
- 这个例子主要展示了通过滑动实现viewflipper页面切换
- Retrofit2 + RxJava + Okhttp + RecyclerView用MVP架构展示数据
- <android> webview与h5的交互——上传文件& 调起本地支付接口&响应原生dialog&back键层级返回
- Android ViewPager切换之PageTransformer接口中transformPage方法position参数使用详解
- 实现点击 WebView 中的图片,调用原生控件展示图片
- MVP接口回调登录
- 使用MVP注册登录模块+封装的OKhttp,拦截器+QQ第三方登录+RecyclerView+SpringView上拉加载下拉刷新网络数据
- 这个例子主要展示了通过点击button实现viewflipper页面切换
- 使用twitter app原生接口登录(Native)
- iOS webView展示gif图(登录时背景图动态gif)
- MVP_注册登录 + 展示数据