今天在一阶段的基础上分配了任务,分为了UI优化,数据库连接,页面事件三个部分
首先是页面事件类的完善
package com.example.runapp;import androIDx.appcompat.app.AlertDialog;import androIDx.appcompat.app.AppCompatActivity;import androID.content.DialogInterface;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.AdapterVIEw;import androID.Widget.ArrayAdapter;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Spinner;import androID.Widget.Toast;import com.example.runapp.Dao.OrderDao;import com.example.runapp.entity.Order;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.List;public class AddOrderActivity extends AppCompatActivity { button btnback,btnsubmit; EditText editTextdescribe,editTextRemark; Spinner spinnerkind,spinnerMoney; String strkind,strmoney; String mintent; Order order; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_add_order); SpinnerKindSet(); SpinnerMoneySet(); editTextdescribe=this.findVIEwByID(R.ID.editText_add_Describe); editTextRemark=this.findVIEwByID(R.ID.editText_add_Remark); //页面传值 mintent=this.getIntent().getStringExtra("ID"); btnsubmit=this.findVIEwByID(R.ID.button_add_Sumbit_main); btnsubmit.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { AlertDialog.Builder mDialog=new AlertDialog.Builder(AddOrderActivity.this); mDialog.setTitle("确认"); mDialog.setMessage("确定添加订单?"); mDialog.setPositivebutton("确认", new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { String kind=strkind; String describe=editTextdescribe.getText().toString(); String money=strmoney; String remark=editTextRemark.getText().toString(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss //获取当前时间 Date date = new Date(System.currentTimeMillis()); String time=simpleDateFormat.format(date); order=new Order(strkind,describe,money,remark,time); Intent intent=new Intent(); if(mintent.equals("1")) { intent.setClass(AddOrderActivity.this,ShopActivity.class); intent.putExtra("order2",order); startActivity(intent); } if(mintent.equals("2")) { intent.setClass(AddOrderActivity.this,PrintActivity.class); intent.putExtra("order2",order); startActivity(intent); } if(mintent.equals("3")) { intent.setClass(AddOrderActivity.this,DeliverActivity.class); intent.putExtra("order2",order); startActivity(intent); } if(mintent.equals("4")) { intent.setClass(AddOrderActivity.this,ElseActivity.class); intent.putExtra("order2",order); startActivity(intent); } if(mintent.equals("5")) { intent.setClass(AddOrderActivity.this,MainActivity.class); intent.putExtra("order2",order); startActivity(intent); } } }); mDialog.setNegativebutton("取消", new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); mDialog.show(); } }); } private voID SpinnerKindSet() { spinnerkind=this.findVIEwByID(R.ID.spinner_add_kind); List<String> List=new ArrayList<String>(); List.add("外卖"); List.add("打印"); List.add("快递"); List.add("其他"); final ArrayAdapter<String> adapter=new ArrayAdapter<>(AddOrderActivity.this,androID.R.layout.simple_spinner_item,List); //adapter.setDropDownVIEwResource(androID.R.layout.simple_spinner_dropdown_item); spinnerkind.setAdapter(adapter); spinnerkind.setonItemSelectedListener(new Spinner.OnItemSelectedListener(){ public voID onItemSelected(AdapterVIEw<?> arg0, VIEw arg1, int arg2, long arg3) { arg0.setVisibility(VIEw.VISIBLE); strkind=(String)spinnerkind.getSelectedItem(); } public voID onnothingSelected(AdapterVIEw<?> arg0) { } }); } private voID SpinnerMoneySet() { spinnerMoney=this.findVIEwByID(R.ID.spinner_add_kindMoney); List<String> List1=new ArrayList<String>(); List1.add("0.7"); List1.add("1"); List1.add("2"); final ArrayAdapter<String> adapter=new ArrayAdapter<>(AddOrderActivity.this,androID.R.layout.simple_spinner_item,List1); //adapter.setDropDownVIEwResource(androID.R.layout.simple_spinner_dropdown_item); spinnerMoney.setAdapter(adapter); spinnerMoney.setonItemSelectedListener(new Spinner.OnItemSelectedListener(){ public voID onItemSelected(AdapterVIEw<?> arg0, VIEw arg1, int arg2, long arg3) { arg0.setVisibility(VIEw.VISIBLE); strmoney=(String)spinnerMoney.getSelectedItem(); } public voID onnothingSelected(AdapterVIEw<?> arg0) { } }); }}
package com.example.runapp;import androIDx.appcompat.app.AppCompatActivity;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.AdapterVIEw;import androID.Widget.ArrayAdapter;import androID.Widget.button;import androID.Widget.ListVIEw;import androID.Widget.Spinner;import com.example.runapp.adapter.AccountItemAdapter;import com.example.runapp.entity.Order;import java.io.Serializable;import java.util.ArrayList;import java.util.List;public class DeliverActivity extends AppCompatActivity {button btn_deliver;ListVIEw ListVIEw;Spinner spinner;Order order_intent; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_deliver); btn_deliver=this.findVIEwByID(R.ID.buttonDeliver_InsIDe); btn_deliver.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Intent intent=new Intent(); intent.setClass(DeliverActivity.this,AddOrderActivity.class); intent.putExtra("ID","3"); startActivity(intent); } }); SpinnerSet(); ListVIEwSet(); } private voID ListVIEwSet() { //数据库补充 final List<Order> order_List=new ArrayList<>(); ListVIEw=this.findVIEwByID(R.ID.ListVIEw_Deliver); order_intent=(Order) this.getIntent().getSerializableExtra("order2"); if(order_intent!=null) { order_List.add(order_intent); } AccountItemAdapter adapter=new AccountItemAdapter(order_List, DeliverActivity.this); ListVIEw.setAdapter(adapter); ListVIEw.setonItemClickListener(new AdapterVIEw.OnItemClickListener() { @OverrIDe public voID onItemClick(AdapterVIEw<?> parent, VIEw vIEw, int position, long ID) { Order order=new Order(); order=order_List.get(position); Intent intent=new Intent(); intent.setClass(DeliverActivity.this,PlayOrderActivity.class); intent.putExtra("order1", (Serializable) order); startActivity(intent); } }); } private voID SpinnerSet() { spinner=this.findVIEwByID(R.ID.spinner_deliver); List<String> List1=new ArrayList<>(); List1.add("按时间"); List1.add("按金额"); final ArrayAdapter<String> adapter=new ArrayAdapter<>(this,androID.R.layout.simple_spinner_item,List1); adapter.setDropDownVIEwResource(androID.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setonItemSelectedListener(new Spinner.OnItemSelectedListener(){ public voID onItemSelected(AdapterVIEw<?> arg0, VIEw arg1, int arg2, long arg3) { arg0.setVisibility(VIEw.VISIBLE); } public voID onnothingSelected(AdapterVIEw<?> arg0) { } }); } private List<Order> getTestDate() { List<Order> result=new ArrayList<Order>(); Order order1=new Order(1,"快递","中通快递","1","送到九栋108","2020-4-28 12:23:11"); Order order2=new Order(2,"快递","圆通快递","1","送到九栋108","2020-4-27 12:33:21"); result.add(order1); result.add(order2); return result; }}
总结
以上是内存溢出为你收集整理的第二阶段十天冲刺第一天全部内容,希望文章能够帮你解决第二阶段十天冲刺第一天所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)