neogz

HCI - DialogOpstine

Aug 31st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. ------------------------------
  2. napraviti java i xml za dijalog
  3. ------------------------------
  4. //// java za dijalog
  5. public class OpstineDijalog extends DialogFragment {
  6. @Nullable
  7. @Override
  8. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  9. return inflater.inflate(R.layout.opstina_dijalog_layout, null);
  10. }
  11.  
  12.  
  13. }
  14.  
  15. ------------------------------
  16. on click
  17. ------------------------------
  18.  
  19. OpstineDijalog dg = new OpstineDijalog();
  20. dg.show(manager,"tagdijaglo");
  21.  
  22. ----------------------------------
  23.  
  24. opstineDijalog.java
  25. ------------------------------
  26. package nedo.hci9;
  27.  
  28. import android.app.DialogFragment;
  29. import android.os.Bundle;
  30. import android.support.annotation.Nullable;
  31. import android.view.LayoutInflater;
  32. import android.view.MenuItem;
  33. import android.view.View;
  34. import android.view.ViewGroup;
  35. import android.widget.AdapterView;
  36. import android.widget.ArrayAdapter;
  37. import android.widget.Button;
  38. import android.widget.ListView;
  39. import android.widget.Toast;
  40.  
  41. /**
  42. * Created by fejzi on 31.08.2016..
  43. */
  44. public class OpstineDijalog extends DialogFragment implements View.OnClickListener, AdapterView.OnItemClickListener{
  45.  
  46. Button yes, no;
  47. Communicator comm;
  48. ListView listica;
  49. String [] dani = {"Ponedjeljak","Utorak", "Srijeda", "Cetvrtak"};
  50.  
  51. @Nullable
  52. @Override
  53. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  54. View view = inflater.inflate(R.layout.opstina_dijalog_layout, null);
  55.  
  56. comm=(Communicator)getActivity();
  57.  
  58. yes = (Button) view.findViewById(R.id.btnDialogYes);
  59. no = (Button) view.findViewById(R.id.btnDialogNo);
  60. yes.setOnClickListener(this);
  61. no.setOnClickListener(this);
  62.  
  63. listica = (ListView) view.findViewById(R.id.listaOpcina);
  64.  
  65. ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,dani);
  66. listica.setAdapter(adapter);
  67. listica.setOnItemClickListener( this);
  68.  
  69.  
  70. return view;
  71. }
  72.  
  73.  
  74.  
  75. @Override
  76. public void onClick(View v) {
  77. if (v.getId() == R.id.btnDialogYes) {
  78. Toast.makeText(getActivity(), "yes je klinut", Toast.LENGTH_LONG).show();
  79. comm.dijalogYes("gopro prosljedjujem u main");
  80. dismiss();
  81. } else {
  82. Toast.makeText(getActivity(), "no je klinut", Toast.LENGTH_LONG).show();
  83. dismiss();
  84. }
  85. }
  86.  
  87. @Override
  88. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  89. dismiss();
  90. Toast.makeText(getActivity(), dani[position], Toast.LENGTH_SHORT)
  91. .show();
  92. }
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. ------------------------------
  101. XML Dialog
  102. ------------------------------
  103.  
  104. <?xml version="1.0" encoding="utf-8"?>
  105. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  106. android:layout_width="match_parent" android:layout_height="match_parent"
  107.  
  108. >
  109.  
  110.  
  111.  
  112.  
  113.  
  114. <TextView
  115. android:layout_width="wrap_content"
  116. android:layout_height="wrap_content"
  117. android:textAppearance="?android:attr/textAppearanceMedium"
  118. android:text="Komanda za zakljucavanje:"
  119. android:id="@+id/lblbeze"
  120. android:layout_alignParentLeft="true"
  121. android:layout_alignParentStart="true"
  122. android:layout_marginTop="10dp"
  123. android:layout_marginBottom="40dp"
  124. android:layout_marginLeft="40dp"/>
  125.  
  126.  
  127.  
  128.  
  129.  
  130. <LinearLayout
  131. android:layout_width="match_parent"
  132. android:layout_height="wrap_content"
  133. android:layout_below="@+id/lblbeze"
  134. android:orientation="horizontal">
  135.  
  136. <Button
  137. android:id="@+id/btnDialogYes"
  138. android:layout_width="0dp"
  139. android:layout_height="wrap_content"
  140. android:layout_alignParentTop="false"
  141. android:layout_weight="0.5"
  142. android:text="Yes"
  143. />
  144.  
  145. <Button
  146. android:id="@+id/btnDialogNo"
  147. android:layout_width="0dp"
  148. android:layout_height="wrap_content"
  149. android:layout_weight="0.5"
  150. android:text="No"
  151. />
  152. </LinearLayout>
  153.  
  154.  
  155. </RelativeLayout>
Add Comment
Please, Sign In to add comment