Android_展示状态
来源:互联网 发布:excel文件数据恢复 编辑:程序博客网 时间:2024/06/13 23:33
将订单的状态展示出来
model层
public class IndentListModel { private HashMap<String, String> map = new HashMap<>(); public void verifySelectCarInfo(int uid,int page,String urlTitle, final IIndentListPresenter iIndentPresenter){ map.put("uid",uid+""); map.put("page",page+""); if ("4".equals(urlTitle)){ }else{ map.put("status",urlTitle); } OkHttpUtils.getInstance().doGet("http://120.27.23.105/product/getOrders", map, new CallBack() { @Override public void onFailed(String msg) { iIndentPresenter.onFailed(); } @Override public void onSuccess(String request) { IndentListBean indentBean = GsonUtils.getInstance().fromJson(request, IndentListBean.class); String code = indentBean.getCode(); if ("0".equals(code)){ List<IndentListBean.DataBean> data = indentBean.getData(); iIndentPresenter.onSuccess(data); }else { iIndentPresenter.onFailed(); } } }); }}
接口
public interface IIndentListPresenter { void onSuccess(List<IndentListBean.DataBean> data); void onFailed();}public interface IIndentListView { void onSuccess(List<IndentListBean.DataBean> data); void onFailed();}
presenter层
public class IndentListPresenter implements IIndentListPresenter { private IIndentListView iIndentView; private IndentListModel indentModel; public IndentListPresenter(IIndentListView iIndentView){ this.iIndentView = iIndentView; indentModel = new IndentListModel(); } //执行集合信息 public void excuteSelectCarData(int uid,int page,String urlTitle){ //传到model indentModel.verifySelectCarInfo(uid,page,urlTitle,this); } @Override public void onSuccess(List<IndentListBean.DataBean> data) { iIndentView.onSuccess(data); } @Override public void onFailed() { iIndentView.onFailed(); }}
view层
public class IndentListActivity extends AppCompatActivity { private TabLayout tl; private ViewPager vp; private List<String> datas = new ArrayList<String>(); private String[] status = new String[]{"4","0","1","2"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_indent_list); tl = (TabLayout) findViewById(R.id.tl); vp = (ViewPager) findViewById(R.id.vp); datas.add("全部"); datas.add("待支付"); datas.add("已支付"); datas.add("已取消"); vp.setAdapter(new MyAdapter(getSupportFragmentManager())); //进行关联 tl.setupWithViewPager(vp); } class MyAdapter extends FragmentPagerAdapter { //带参的构造方法 public MyAdapter(FragmentManager fm) { super(fm); } @Override public int getCount() { return datas.size(); } //返回选项卡的文本 ,,,添加选项卡 @Override public CharSequence getPageTitle(int position) { return datas.get(position); } @Override public Fragment getItem(int position) { //创建fragment对象并返回 Bundle bundle = new Bundle(); bundle.putString("url", status[position]); //实例化Fragment AllFragment allFragment = new AllFragment(); allFragment.setArguments(bundle); return allFragment; } }}
view的布局
<RelativeLayout 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.example.jkr.moni2.indent.IndentListActivity"> <android.support.design.widget.TabLayout android:id="@+id/tl" android:layout_width="match_parent" android:layout_height="50dp" app:tabGravity="fill" app:tabIndicatorColor="@color/colorAccent" app:tabMode="fixed" app:tabTextColor="@color/colorPrimary" /> <android.support.v4.view.ViewPager android:id="@+id/vp" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/tl" ></android.support.v4.view.ViewPager></RelativeLayout>
适配器
public class XRAdapter extends RecyclerView.Adapter<XRAdapter.ViewHolder>{ private Context context; private List<IndentListBean.DataBean> list; public XRAdapter(Context context, List<IndentListBean.DataBean> list) { this.context = context; this.list = list; } @Override public XRAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context,R.layout.indent_item_layout,null); view.setMinimumWidth(620); ViewHolder holder = new ViewHolder(view); return holder; } @Override public void onBindViewHolder(final XRAdapter.ViewHolder holder, int position) { holder.title.setText(list.get(position).getTitle()); holder.price.setText(list.get(position).getPrice()+"¥"); holder.createtime.setText(list.get(position).getCreatetime()); int status = list.get(position).getStatus(); if (status==0){ holder.status.setText("待支付"); holder.indentBtn.setText("取消订单"); }else if (status==1){ holder.status.setText("已支付"); holder.indentBtn.setText("查看订单"); }else if(status==2){ holder.status.setText("已取消"); holder.indentBtn.setText("查看订单"); } holder.indentBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (holder.indentBtn.getText().equals("查看订单")){ Toast.makeText(context,"订单已经取消过了",Toast.LENGTH_SHORT).show(); }else{ new AlertDialog.Builder(context) .setTitle("提示") .setMessage("确定是否取消订单") .setNegativeButton("取消", null)//设置取消按钮 null为按钮的点击事件 .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } })//设置确定按钮 null为按钮的点击事件 .show(); } } }); } @Override public int getItemCount() { Log.e("IIII",list.size()+""); return list.size(); } class ViewHolder extends RecyclerView.ViewHolder{ TextView title; TextView price; TextView createtime; TextView status; Button indentBtn; public ViewHolder(View itemView) { super(itemView); title = itemView.findViewById(R.id.title); price = itemView.findViewById(R.id.price); createtime = itemView.findViewById(R.id.createtime); status = itemView.findViewById(R.id.status); indentBtn = itemView.findViewById(R.id.indentBtn); } }}
适配器的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="0dp" android:layout_weight="7" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="订单测试标题3381" /> <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="价格:1.10¥" /> <TextView android:id="@+id/createtime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0000-00-00T00:00:00" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_weight="3" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/status" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:text="未支付" /> <Button android:id="@+id/indentBtn" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="2" android:text="取消订单" /> </LinearLayout></LinearLayout>
阅读全文
0 0
- Android_展示状态
- Android_判断手机网络状态
- Android_请求网络数据展示到Listview
- android_判断网络链接状态-ConnectivityManager
- android_网络判断,Greendao,retrofit,eventbus结合展示数据
- Android_实现商品详情的展示页及布局
- Android_程序判断手机ROOT状态,获取ROOT权限
- Android_滚动状态ScrollView实现标题的悬浮和渐隐
- android_购物车三种状态之拦截器 post请求
- 106_不同状态的页面展示
- 根据选择状态展示对应数据列表
- jira工作流状态修改展示Screen弹出框
- Android通用的EmptyLayout-展示不用状态的界面
- Android通用的EmptyLayout-展示不用状态的界面
- esayui-ajax(不同的状态展示不同的按钮)
- Android:使用LoadingLayout来展示加载数据时不同状态
- android_广播者_只能用代码注册(动态注册)的广播接收者_监听屏幕的状态
- android_对话框
- centos7 连接不上mongodb
- MVP基类介绍
- thinkphp开发小程序之小程序发起微信支付
- 1.1.1作为序言
- Delphi中组件Panel、Splitter、GroupBox、按钮组件(CheckBox...)、计时器、滚动条、多选卡
- Android_展示状态
- POS机代理赚钱吗 POS机如何代理
- 使用第三方框架PagerSlidingTabStrip实现横向滑动目录
- 5-2 派生类的构造函数
- 20171221 自省
- 简单的表格列表切换展示
- 属性动画
- ARM全解析 ARM8/ARM7/A9/A15等区别
- 蘑菇街搜索与推荐架构