今天在一阶段的基础上分配了任务,分为了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; } }