今天的任务,底部导航栏和主页fragment.
订单fragment
package com.example.runapp.fragment; import android.content.Intent; import android.os.Bundle; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; import com.example.runapp.PlayOrderActivity; import com.example.runapp.R; import com.example.runapp.SubmitOrderActivity; import com.example.runapp.adapter.AccountItemAdapter; import com.example.runapp.entity.Order; import java.io.Serializable; import java.util.ArrayList; import java.util.List; /** * A simple {@link Fragment} subclass. */ public class DingDanFragment extends Fragment { ListView listViewin,listViewout; View mRootView; Order order_intent_in=null,order_intent_out=null; public DingDanFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment mRootView=inflater.inflate(R.layout.fragment_ding_dan, container, false); InitView(); return mRootView; } private void InitView() { refreshinData(); refresOutData(); } private void refreshinData() { listViewin=mRootView.findViewById(R.id.listView_insubmit); final List<Order> orderList=getTestDate(); order_intent_in=(Order) getActivity().getIntent().getSerializableExtra("order2"); if(order_intent_in!=null) { orderList.add(order_intent_in); } AccountItemAdapter adapter=new AccountItemAdapter(orderList,getActivity()); listViewin.setAdapter(adapter); listViewin.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Order order=new Order(); order=orderList.get(position); Intent intent=new Intent(); intent.putExtra("kind","1"); intent.setClass(getActivity(), SubmitOrderActivity.class); intent.putExtra("order3", (Serializable) order); startActivity(intent); } }); } private void refresOutData() { listViewout=mRootView.findViewById(R.id.listView_outsubmit); final List<Order> orderList=getTestDate(); order_intent_out=(Order) getActivity().getIntent().getSerializableExtra("submitOrder"); if(order_intent_out!=null) { orderList.add(order_intent_out); } AccountItemAdapter adapter=new AccountItemAdapter(orderList,getActivity()); listViewout.setAdapter(adapter); listViewout.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Order order=new Order(); order=orderList.get(position); Intent intent=new Intent(); intent.setClass(getActivity(), SubmitOrderActivity.class); intent.putExtra("kind","1"); intent.putExtra("order4", (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,"快递","中通快递t082","1","九栋108","2020-4-28 11:33:21"); result.add(order1); result.add(order2); return result; } }
package com.example.runapp.fragment; import android.content.Context; import android.net.Uri; import android.os.Bundle; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.runapp.R; public class personFragment extends Fragment { public personFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_person, container, false); } }
package com.example.runapp.fragment; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.Spinner; import com.example.runapp.AddOrderActivity; import com.example.runapp.DeliverActivity; import com.example.runapp.ElseActivity; import com.example.runapp.PlayOrderActivity; import com.example.runapp.PrintActivity; import com.example.runapp.R; import com.example.runapp.ShopActivity; 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 SummaryFragment extends Fragment { Button btnShop,btnPrint,btnDeliver,btnElse,btnAddOrder; Spinner spinner; View mRootView; ListView listView; Order order_intent=null; public SummaryFragment() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment mRootView=inflater.inflate(R.layout.fragment_summary, container, false); InitView(); //下拉框 getSpinner(); //listview refreshData(); return mRootView; } private void InitView() { btnShop=mRootView.findViewById(R.id.buttonShop); btnDeliver=mRootView.findViewById(R.id.buttonDeliver); btnPrint=mRootView.findViewById(R.id.buttonPrint); btnElse=mRootView.findViewById(R.id.buttonElse); btnAddOrder=mRootView.findViewById(R.id.buttonPlayOrder); btnShop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(getActivity(), ShopActivity.class); startActivity(intent); } }); btnPrint.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(getActivity(), PrintActivity.class); startActivity(intent); } }); btnDeliver.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(getActivity(), DeliverActivity.class); startActivity(intent); } }); btnElse.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(getActivity(), ElseActivity.class); startActivity(intent); } }); btnAddOrder.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(); intent.setClass(getActivity(), AddOrderActivity.class); intent.putExtra("id","5"); startActivity(intent); } }); } private void refreshData() { listView=mRootView.findViewById(R.id.listview_main); final List<Order> orderList=getTestDate(); order_intent=(Order) getActivity().getIntent().getSerializableExtra("order2"); if(order_intent!=null) { orderList.add(order_intent); } AccountItemAdapter adapter=new AccountItemAdapter(orderList,getActivity()); 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=orderList.get(position); Intent intent=new Intent(); intent.setClass(getActivity(),PlayOrderActivity.class); intent.putExtra("order1", (Serializable) order); startActivity(intent); } }); } private void getSpinner() { spinner=mRootView.findViewById(R.id.action_spinner); List<String> list1=new ArrayList<>(); list1.add("按时间"); list1.add("按金额"); final ArrayAdapter<String> adapter=new ArrayAdapter<>(getActivity(),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,"外卖","九栋108一份炒面","1","不放辣椒哦","2020-4-28 11:23:11"); Order order2=new Order(2,"快递","中通快递t082","1","九栋108","2020-4-28 11:33:21"); result.add(order1); result.add(order2); return result; } }