今天主要任务是订单详细页面的完善以及数据的传输
效果图:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="60dp" xmlns:card_view="http://schemas.android.com/tools" android:layout_marginBottom="10dp" card_view:cardCornerRadius="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/blanck_shape" xmlns:app="http://schemas.android.com/apk/res-auto"> <TextView android:id="@+id/textViewCategory" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="5dp" android:layout_marginLeft="10dp" android:text="类别" /> <TextView android:id="@+id/textViewMoney" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginRight="30dp" android:layout_marginTop="5dp" android:textSize="20sp" android:textColor="@color/red" android:text="500"/> <TextView android:id="@+id/textViewDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="10dp" android:text="2020/4/24" android:layout_marginRight="30dp"/> <TextView android:id="@+id/textViewRemark" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/textViewDate" android:layout_marginRight="50dp" android:layout_marginBottom="10dp" android:layout_alignParentBottom="true" android:text="备注" /> <ImageView android:id="@+id/imageViewIcon" android:layout_below="@id/textViewCategory" android:layout_width="30dp" android:layout_height="30dp" android:layout_marginLeft="10dp" android:layout_marginBottom="10dp" app:srcCompat="@drawable/book_icon" /> <ImageView android:id="@+id/imageViewDelete" android:layout_width="10dp" android:layout_height="10dp" android:scaleType="fitXY" app:srcCompat="@drawable/logo_wrong" android:layout_alignParentRight="true" android:layout_centerVertical="true" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="60dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:id="@+id/list_view_item" android:background="@drawable/blanck_shape" android:layout_marginBottom="10dp" > <TextView android:id="@+id/textViewCategory" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="5dp" android:layout_marginLeft="10dp" android:text="类别" /> <TextView android:id="@+id/textViewMoney" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/textViewDate" android:layout_marginRight="50dp" android:layout_marginTop="5dp" android:textSize="20sp" android:layout_centerHorizontal="true" android:textColor="@color/red" android:text="500"/> <TextView android:id="@+id/textViewDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_marginBottom="10dp" android:text="2020/4/24" android:layout_marginRight="10dp"/> <TextView android:id="@+id/textViewDescribe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginBottom="10dp" android:layout_alignParentBottom="true" android:text="描述" /> <ImageView android:id="@+id/imageViewIcon" android:layout_below="@id/textViewCategory" android:layout_width="30dp" android:layout_height="30dp" android:layout_marginLeft="10dp" android:layout_marginBottom="10dp" app:srcCompat="@drawable/baby_icon" /> </RelativeLayout>
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) { } }); } }