第二阶段十天冲刺第三天

完善下订单,快递等页面的跳转等优化

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.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);

                        }







                    }

 

posted @ 2020-05-25 13:57  铁大跑腿  阅读(159)  评论(0编辑  收藏  举报