Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. public class DisplayProduct extends AppCompatActivity {
  2.  
  3. ListView listView;
  4. SQLiteDatabase sqLiteDatabase;
  5. DatabaseHelper databaseHelper;
  6. Cursor cursor;
  7. ListDataAdapter listDataAdapter;
  8.  
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_display_product);
  13.  
  14. listView = (ListView)findViewById(R.id.listView);
  15. listDataAdapter = new ListDataAdapter(getApplicationContext(),R.layout.display_product_row);
  16. listView.setAdapter(listDataAdapter);
  17.  
  18. databaseHelper = new DatabaseHelper(getApplicationContext());
  19.  
  20. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  21.  
  22. @Override
  23. public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  24. {
  25. //Object data = parent.getItemAtPosition(position);
  26. //String value = data.toString();
  27. Intent intent = new Intent(DisplayProduct.this,LocationDetail.class);
  28. Object data = parent.getItemAtPosition(position);
  29. String message = data.toString();
  30. intent.putExtra("Contacts", message);
  31. startActivity(intent);
  32.  
  33.  
  34.  
  35.  
  36. }
  37. });
  38. sqLiteDatabase = databaseHelper.getReadableDatabase();
  39. cursor = databaseHelper.getInformations(sqLiteDatabase);
  40. if(cursor.moveToFirst())
  41. {
  42. do {
  43.  
  44. String contact,location,issue;
  45. contact = cursor.getString(0);
  46. location = cursor.getString(1);
  47. issue = cursor.getString(2);
  48. Information information = new Information(contact,location,issue);
  49. listDataAdapter.add(information);
  50.  
  51.  
  52. } while (cursor.moveToNext());
  53. }
  54. }
  55.  
  56. public class LocationDetail extends AppCompatActivity {
  57.  
  58. TextView nametxt;
  59.  
  60.  
  61.  
  62. @Override
  63. protected void onCreate(Bundle savedInstanceState) {
  64. super.onCreate(savedInstanceState);
  65. setContentView(R.layout.activity_location_detail);
  66.  
  67. nametxt= (TextView) findViewById(R.id.textView66);
  68.  
  69. Intent intent = getIntent();
  70. String value = intent.getStringExtra("Contacts");
  71. nametxt.setText(value);
  72.  
  73.  
  74.  
  75. }
  76.  
  77. @Override
  78. public boolean onCreateOptionsMenu(Menu menu) {
  79. // Inflate the menu; this adds items to the action bar if it is present.
  80. getMenuInflater().inflate(R.menu.menu_location_detail, menu);
  81. return true;
  82. }
  83.  
  84. @Override
  85. public boolean onOptionsItemSelected(MenuItem item) {
  86. // Handle action bar item clicks here. The action bar will
  87. // automatically handle clicks on the Home/Up button, so long
  88. // as you specify a parent activity in AndroidManifest.xml.
  89. int id = item.getItemId();
  90.  
  91. //noinspection SimplifiableIfStatement
  92. if (id == R.id.action_settings) {
  93. return true;
  94. }
  95.  
  96. return super.onOptionsItemSelected(item);
  97. }
  98.  
  99. public class ListDataAdapter extends ArrayAdapter {
  100. List list = new ArrayList();
  101. public ListDataAdapter(Context context, int resource) {
  102. super(context, resource);
  103. }
  104.  
  105. static class LayoutHandler
  106. {
  107. TextView Contact,Location,Issue;
  108. }
  109.  
  110. @Override
  111. public void add(Object object) {
  112. super.add(object);
  113. list.add(object);
  114.  
  115. }
  116.  
  117. @Override
  118. public int getCount() {
  119. return list.size();
  120. }
  121.  
  122. @Override
  123. public Object getItem(int position) {
  124. return list.get(position);
  125. }
  126.  
  127. @Override
  128. public View getView(int position, View convertView, ViewGroup parent) {
  129.  
  130. View row = convertView;
  131. LayoutHandler layoutHandler;
  132. if (row == null) {
  133. LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  134. row = layoutInflater.inflate(R.layout.display_product_row, parent, false);
  135. layoutHandler = new LayoutHandler();
  136. layoutHandler.Contact = (TextView) row.findViewById(R.id.textView8);
  137. layoutHandler.Location = (TextView) row.findViewById(R.id.textView18);
  138. layoutHandler.Issue = (TextView) row.findViewById(R.id.textView90);
  139. row.setTag(layoutHandler);
  140.  
  141. } else {
  142. layoutHandler = (LayoutHandler) row.getTag();
  143.  
  144.  
  145. }
  146.  
  147. Information information = (Information) this.getItem(position);
  148. layoutHandler.Contact.setText(information.getContact());
  149. layoutHandler.Location.setText(information.getLocation());
  150. layoutHandler.Issue.setText(information.getIssue());
  151.  
  152. return row;
  153.  
  154.  
  155.  
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement