全部页面的设计和跳转。
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.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; public class ShopActivity extends AppCompatActivity { Button btn_shop; ListView listView; Spinner spinner; Order order_intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shop); btn_shop=this.findViewById(R.id.buttonShop_Inside); btn_shop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(ShopActivity.this,AddOrderActivity.class); intent.putExtra("id","1"); startActivity(intent); } }); //下拉框 SpinnerSet(); //列表 ListViewSet(); } private void SpinnerSet() { spinner=this.findViewById(R.id.spinner_shop); 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 void ListViewSet() { //数据库补充 final List<Order> order_list=getTestDate(); listView=this.findViewById(R.id.listView_shop); order_intent=(Order) this.getIntent().getSerializableExtra("order2"); if(order_intent!=null) { order_list.add(order_intent); } AccountItemAdapter adapter=new AccountItemAdapter(order_list, ShopActivity.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(ShopActivity.this,PlayOrderActivity.class); intent.putExtra("order1", (Serializable) order); startActivity(intent); } }); } private List<Order> getTestDate() { List<Order> result=new ArrayList<Order>(); Order order1=new Order(1,"外卖","九栋108一份炒面","1","不放辣椒哦","2020-4-28 11:23:11"); Order order2=new Order(2,"外卖","九栋108一份米线","1","多放辣椒哦","2020-4-28 11:33:21"); result.add(order1); result.add(order2); return result; } }
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 PrintActivity extends AppCompatActivity { Button btn_Print; ListView listView; Spinner spinner; Order order_intent; Order orderFormal=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_print); orderFormal=(Order) this.getIntent().getSerializableExtra("order1"); btn_Print=this.findViewById(R.id.buttonPrint_Inside); SpinnerSet(); btn_Print.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(PrintActivity.this,AddOrderActivity.class); intent.putExtra("id","2"); startActivity(intent); } }); ListViewSet(); } private void ListViewSet() { //数据库补充 final List<Order> order_list=getTestDate(); listView=this.findViewById(R.id.listView_print); order_intent=(Order) this.getIntent().getSerializableExtra("order2"); if(order_intent!=null) { order_list.add(order_intent); } AccountItemAdapter adapter=new AccountItemAdapter(order_list, PrintActivity.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(PrintActivity.this,PlayOrderActivity.class); intent.putExtra("order1", (Serializable) order); startActivity(intent); } }); } private void SpinnerSet() { spinner=this.findViewById(R.id.spinner_Print); 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); if(orderFormal!=null) { for(int i=0;i<list1.size();i++) { if(orderFormal.getMoney().equals(list1.get(i))) { spinner.setSelection(i,true); } } } 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,"打印","九栋108一份","1","a4纸哦","2020-4-28 11:24:21"); Order order2=new Order(2,"打印","九栋108一份","1","a4纸哦","2020-4-28 11:34:24"); result.add(order1); result.add(order2); return result; } }