Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyListFragment extends Fragment implements
- android.widget.CompoundButton.OnCheckedChangeListener {
- ListView lv;
- ArrayList<Planet> planetList;
- PlanetAdapter plAdapter;
- BirraAdapter biAdapter;
- PlanetAdapter.PlanetHolder holder;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_list2, container, false);
- Button mButton = (Button) rootView.findViewById(R.id.button);
- mButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- showResult(v);
- }
- });
- //return inflater.inflate(R.layout.fragment_list2, container, false);
- return rootView;
- }
- @Override
- public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- lv = (ListView)getView().findViewById(R.id.listview);
- displayPlanetList();
- }
- private void displayPlanetList() {
- planetList = new ArrayList<Planet>();
- planetList.add(new Planet("Margherita", 6, "€"));
- planetList.add(new Planet("Diavola", 7,"€"));
- planetList.add(new Planet("Bufalina", 5,"€"));
- planetList.add(new Planet("Marinara", 5,"€"));
- planetList.add(new Planet("Viennese", 4, "€"));
- plAdapter = new PlanetAdapter(planetList, getContext()) {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- int pos = lv.getPositionForView(buttonView);
- if (pos != ListView.INVALID_POSITION) {
- Planet p = planetList.get(pos);
- p.setSelected(isChecked);
- /*Toast.makeText(
- getActivity(),
- "Clicked on Pizza: " + p.getName() + ". State: is "
- + isChecked, Toast.LENGTH_SHORT).show();*/
- }
- }
- };
- lv.setAdapter(plAdapter);
- }
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- /*int pos = lv.getPositionForView(buttonView);
- if (pos != ListView.INVALID_POSITION) {
- Planet p = planetList.get(pos);
- p.setSelected(isChecked);
- *//*Toast.makeText(
- getActivity(),
- "Clicked on Planet: " + p.getName() + ". State: is "
- + isChecked, Toast.LENGTH_SHORT).show();*//*
- }*/
- }
- public void showResult(View v) {
- String result2 = "Selected Product are :";
- int totalAmount2=0;
- String a="";
- for (Birra b : biAdapter.getBox()){
- if (b.selected){
- result2 += "\n" + b.name+" "+b.distance+"€"+"q.tà :"+b.getQuantità();
- int quantitaInt= Integer.parseInt(b.getQuantità());
- totalAmount2+=b.distance * quantitaInt;
- //a=String.valueOf(totalAmount);
- }
- }
- /* for (Planet p : plAdapter.getBox()) {
- if (p.selected){
- result += "\n" + p.name+" "+p.distance+"€"+"q.tà :"+p.getQuantità();
- int quantitaInt= Integer.parseInt(p.getQuantità() );
- totalAmount+=p.distance * quantitaInt;
- //a=String.valueOf(totalAmount);
- }
- }*/
- //Toast.makeText(getActivity(), result + "\n" + "Total Amount:=" + totalAmount + "€", Toast.LENGTH_LONG).show();
- Toast.makeText(getActivity(), result2 + "\n" + "Total Amount:=" + totalAmount2 + "€", Toast.LENGTH_LONG).show();
- /*Bundle bun2 = new Bundle();
- bun2.putString("scelta", result);
- TwoFragment fgsearch2 = new TwoFragment();
- fgsearch2.setArguments(bun2);
- android.support.v4.app.FragmentTransaction transaction2 = getActivity().getSupportFragmentManager().beginTransaction();
- transaction2.replace(R.id.content_main, fgsearch2);
- transaction2.commit();
- Bundle bun = new Bundle();
- bun.putString("totale", a);
- TwoFragment fgsearch = new TwoFragment();
- fgsearch.setArguments(bun);
- android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
- transaction.replace(R.id.content_main2, fgsearch);
- transaction.commit();
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement