Advertisement
Guest User

Select.java

a guest
Nov 29th, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. public class Select extends Activity
  2. {
  3. private Header header;
  4. private ListView lvUsers;
  5. private ArrayList<UserBO> mListUsers;
  6. private SharedPreferences mPreferences1;
  7. private SharedPreferences mPreferences2;
  8. String myString1,query,query1,query2,query3,query4,categoryid,un;
  9. int myStr,j;
  10.  
  11. public static RadioGroup radioGroup;
  12.  
  13. public static RadioButton op1;
  14. static RadioButton op2;
  15. static RadioButton op3;
  16. static RadioButton op4;
  17. static RadioButton op5;
  18. static String answer=null;
  19. public static String op1val=null;
  20.  
  21.  
  22. ImageView im;
  23. //EditText text1;
  24. /** Called when the activity is first created. */
  25. @Override
  26. public void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. System.out.println("before select ");
  29. setContentView(R.layout.select);
  30.  
  31.  
  32.  
  33. System.out.println("after select ");
  34. header = (Header) findViewById(R.id.layoutHeader);
  35.  
  36.  
  37. mListUsers = getUsers();
  38.  
  39. lvUsers = (ListView) findViewById(R.id.lv_user);
  40. lvUsers.setAdapter(new ListAdapter(this, R.id.lv_user, mListUsers));
  41.  
  42.  
  43. }
  44.  
  45. public ArrayList<UserBO> getUsers(){
  46.  
  47. DBAdapter dbAdapter=DBAdapter.getDBAdapterInstance(this);
  48. try {
  49. dbAdapter.createDataBase();
  50. } catch (IOException e) {
  51. Log.i("*** select ",e.getMessage());
  52. }
  53.  
  54. mPreferences1 = getSharedPreferences("CurrentUser1", 0);
  55.  
  56.  
  57. myString1 = mPreferences1.getString("categ",categoryid);
  58.  
  59. Log.i("mystring1", "" +myString1);
  60.  
  61. dbAdapter.openDataBase();
  62.  
  63. query="select * from tbliapp where category_id="+myString1+" order by RANDOM() LIMIT 1;";
  64. //////// Log.i("j value ", myString1);
  65.  
  66.  
  67.  
  68. ArrayList<ArrayList<String>> stringList = dbAdapter.selectRecordsFromDBList(query, null);
  69. dbAdapter.close();
  70.  
  71. ArrayList<UserBO> usersList = new ArrayList<UserBO>();
  72.  
  73. for (int i = 0; i < stringList.size(); i++) {
  74. ArrayList<String> list = stringList.get(i);
  75.  
  76.  
  77.  
  78.  
  79.  
  80. UserBO user = new UserBO();
  81. AppConstants.alConductedQuestions.add(user);
  82. System.out.println("mListUsers");
  83. System.out.println(user);
  84. try {
  85.  
  86. //System.out.println(list);
  87. //System.out.println(user);
  88. user.id = Integer.parseInt(list.get(0));
  89. user.name = list.get(2);
  90.  
  91. user.question = list.get(3);
  92. user.option1 = list.get(4);
  93. user.option2 = list.get(5);
  94. user.option3 = list.get(6);
  95. user.option4 = list.get(7);
  96. user.option5 = list.get(8);
  97. //user.pictures = list.get(9);
  98. user.answer = (list.get(10));
  99.  
  100. } catch (Exception e) {
  101. Log.i("***" + Select.class.toString(), e.getMessage());
  102. }
  103. usersList.add(user);
  104. System.out.println(list);
  105.  
  106.  
  107. }
  108. //System.out.println(usersList);
  109.  
  110. return usersList;
  111.  
  112. }
  113.  
  114.  
  115.  
  116. // ***ListAdapter***
  117. private class ListAdapter extends ArrayAdapter<UserBO> { // --CloneChangeRequired
  118. private ArrayList<UserBO> mList; // --CloneChangeRequired
  119. private Context mContext;
  120.  
  121. public ListAdapter(Context context, int textViewResourceId,ArrayList<UserBO> list) { // --CloneChangeRequired
  122. super(context, textViewResourceId, list);
  123. //System.out.println(list);
  124. this.mList = list;
  125. this.mContext = context;
  126.  
  127.  
  128. }
  129.  
  130. public View getView(int position, View convertView, ViewGroup parent){
  131. View view = convertView;
  132. try{
  133. if (view == null) {
  134. LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  135. view = vi.inflate(R.layout.list_item, null);
  136. // --CloneChangeRequired(list_item)
  137. }
  138. final UserBO listItem = mList.get(position); // --CloneChangeRequired
  139. if (listItem != null) {
  140. // setting list_item views
  141. ( (TextView) view.findViewById(R.id.tv_question) ).setText( listItem.getQuestion()+"");
  142. ArrayList<UserBO> mList1;
  143.  
  144. op1=(RadioButton)findViewById(R.id.option1);
  145. op2=(RadioButton)findViewById(R.id.option2);
  146. op3=(RadioButton)findViewById(R.id.option3);
  147. op4=(RadioButton)findViewById(R.id.option4);
  148. op5=(RadioButton)findViewById(R.id.option5);
  149. System.out.println("after lv users ");
  150. op1.setText(listItem.getOption1());
  151.  
  152.  
  153. op2.setText(listItem.getOption2());
  154.  
  155.  
  156. op3.setText(listItem.getOption3());
  157.  
  158.  
  159. op4.setText(listItem.getOption4());
  160.  
  161.  
  162. op5.setText(listItem.getOption5());
  163.  
  164. System.out.println(listItem.getId());
  165. RadioGroup mRadioGroup = (RadioGroup) findViewById(R.id.rdbGp1);
  166. int checkedRadioButton = mRadioGroup.getCheckedRadioButtonId();
  167.  
  168. String radioButtonSelected = "";
  169.  
  170. switch (checkedRadioButton) {
  171. case R.id.option1 : radioButtonSelected = "radiobutton1";
  172. break;
  173. case R.id.option2 : radioButtonSelected = "radiobutton2";
  174. break;
  175. case R.id.option3 : radioButtonSelected = "radiobutton3";
  176. break;
  177. }
  178. System.out.println("radioButtonSelected");
  179. System.out.println(radioButtonSelected);
  180. /*
  181. if(op1.isChecked()==true)
  182.  
  183. {
  184. answer="1";
  185. Log.i("answer",answer);
  186. }
  187. if(op2.isChecked()==true)
  188.  
  189. {
  190. answer="2";
  191. Log.i("answer",answer);
  192. } else if(op3.isChecked()==true)
  193. {
  194. answer="3";
  195. Log.i("answer",answer);
  196. }else if(op4.isChecked()==true)
  197.  
  198. {
  199. answer="4";
  200. Log.i("answer",answer);
  201. }else if(op5.isChecked()==true)
  202.  
  203. {
  204. answer="5";
  205. Log.i("answer",answer);
  206. }
  207.  
  208.  
  209. ///////////////////////////////
  210. Log.i("answer",answer);*/
  211. }
  212. }
  213. catch(Exception e){
  214.  
  215. String err = (e.getMessage()==null)?"hii":e.getMessage();
  216. Log.e("sdcard-err2:",err);
  217. //Log.i(Select.ListAdapter.class.toString(), e.getMessage());
  218. }
  219. return view;
  220.  
  221.  
  222.  
  223. }
  224.  
  225.  
  226. }
  227.  
  228.  
  229. }
  230.  
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement