Advertisement
markella92

Untitled

May 12th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. public class MyListFragment extends Fragment implements
  2. android.widget.CompoundButton.OnCheckedChangeListener {
  3.  
  4. ListView lv;
  5. ArrayList<Planet> planetList;
  6. PlanetAdapter plAdapter;
  7. BirraAdapter biAdapter;
  8. PlanetAdapter.PlanetHolder holder;
  9.  
  10.  
  11. @Override
  12. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  13. Bundle savedInstanceState) {
  14. // Inflate the layout for this fragment
  15.  
  16. ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_list2, container, false);
  17.  
  18.  
  19. Button mButton = (Button) rootView.findViewById(R.id.button);
  20. mButton.setOnClickListener(new View.OnClickListener() {
  21. public void onClick(View v) {
  22. showResult(v);
  23.  
  24.  
  25. }
  26. });
  27. //return inflater.inflate(R.layout.fragment_list2, container, false);
  28. return rootView;
  29. }
  30.  
  31.  
  32. @Override
  33. public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  34. super.onViewCreated(view, savedInstanceState);
  35.  
  36.  
  37. lv = (ListView)getView().findViewById(R.id.listview);
  38. displayPlanetList();
  39. }
  40.  
  41.  
  42. private void displayPlanetList() {
  43.  
  44. planetList = new ArrayList<Planet>();
  45. planetList.add(new Planet("Margherita", 6, "€"));
  46. planetList.add(new Planet("Diavola", 7,"€"));
  47. planetList.add(new Planet("Bufalina", 5,"€"));
  48. planetList.add(new Planet("Marinara", 5,"€"));
  49. planetList.add(new Planet("Viennese", 4, "€"));
  50.  
  51. plAdapter = new PlanetAdapter(planetList, getContext()) {
  52. @Override
  53. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  54.  
  55. int pos = lv.getPositionForView(buttonView);
  56. if (pos != ListView.INVALID_POSITION) {
  57. Planet p = planetList.get(pos);
  58. p.setSelected(isChecked);
  59.  
  60.  
  61. /*Toast.makeText(
  62. getActivity(),
  63. "Clicked on Pizza: " + p.getName() + ". State: is "
  64. + isChecked, Toast.LENGTH_SHORT).show();*/
  65. }
  66.  
  67.  
  68. }
  69. };
  70. lv.setAdapter(plAdapter);
  71. }
  72.  
  73.  
  74.  
  75.  
  76. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  77.  
  78. /*int pos = lv.getPositionForView(buttonView);
  79. if (pos != ListView.INVALID_POSITION) {
  80. Planet p = planetList.get(pos);
  81. p.setSelected(isChecked);
  82.  
  83.  
  84. *//*Toast.makeText(
  85. getActivity(),
  86. "Clicked on Planet: " + p.getName() + ". State: is "
  87. + isChecked, Toast.LENGTH_SHORT).show();*//*
  88. }*/
  89.  
  90. }
  91.  
  92.  
  93. public void showResult(View v) {
  94. String result2 = "Selected Product are :";
  95. int totalAmount2=0;
  96.  
  97. String a="";
  98. for (Birra b : biAdapter.getBox()){
  99.  
  100. if (b.selected){
  101.  
  102. result2 += "\n" + b.name+" "+b.distance+"€"+"q.tà :"+b.getQuantità();
  103. int quantitaInt= Integer.parseInt(b.getQuantità());
  104. totalAmount2+=b.distance * quantitaInt;
  105. //a=String.valueOf(totalAmount);
  106.  
  107.  
  108. }
  109. }
  110. /* for (Planet p : plAdapter.getBox()) {
  111. if (p.selected){
  112.  
  113. result += "\n" + p.name+" "+p.distance+"€"+"q.tà :"+p.getQuantità();
  114. int quantitaInt= Integer.parseInt(p.getQuantità() );
  115. totalAmount+=p.distance * quantitaInt;
  116. //a=String.valueOf(totalAmount);
  117.  
  118.  
  119. }
  120. }*/
  121. //Toast.makeText(getActivity(), result + "\n" + "Total Amount:=" + totalAmount + "€", Toast.LENGTH_LONG).show();
  122. Toast.makeText(getActivity(), result2 + "\n" + "Total Amount:=" + totalAmount2 + "€", Toast.LENGTH_LONG).show();
  123.  
  124. /*Bundle bun2 = new Bundle();
  125. bun2.putString("scelta", result);
  126. TwoFragment fgsearch2 = new TwoFragment();
  127. fgsearch2.setArguments(bun2);
  128. android.support.v4.app.FragmentTransaction transaction2 = getActivity().getSupportFragmentManager().beginTransaction();
  129. transaction2.replace(R.id.content_main, fgsearch2);
  130. transaction2.commit();
  131.  
  132.  
  133. Bundle bun = new Bundle();
  134. bun.putString("totale", a);
  135. TwoFragment fgsearch = new TwoFragment();
  136. fgsearch.setArguments(bun);
  137. android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
  138. transaction.replace(R.id.content_main2, fgsearch);
  139. transaction.commit();
  140. */
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. }
  155.  
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement