Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DisplayProduct extends AppCompatActivity {
- ListView listView;
- SQLiteDatabase sqLiteDatabase;
- DatabaseHelper databaseHelper;
- Cursor cursor;
- ListDataAdapter listDataAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_display_product);
- listView = (ListView)findViewById(R.id.listView);
- listDataAdapter = new ListDataAdapter(getApplicationContext(),R.layout.display_product_row);
- listView.setAdapter(listDataAdapter);
- databaseHelper = new DatabaseHelper(getApplicationContext());
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id)
- {
- //Object data = parent.getItemAtPosition(position);
- //String value = data.toString();
- Intent intent = new Intent(DisplayProduct.this,LocationDetail.class);
- Object data = parent.getItemAtPosition(position);
- String message = data.toString();
- intent.putExtra("Contacts", message);
- startActivity(intent);
- }
- });
- sqLiteDatabase = databaseHelper.getReadableDatabase();
- cursor = databaseHelper.getInformations(sqLiteDatabase);
- if(cursor.moveToFirst())
- {
- do {
- String contact,location,issue;
- contact = cursor.getString(0);
- location = cursor.getString(1);
- issue = cursor.getString(2);
- Information information = new Information(contact,location,issue);
- listDataAdapter.add(information);
- } while (cursor.moveToNext());
- }
- }
- public class LocationDetail extends AppCompatActivity {
- TextView nametxt;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_location_detail);
- nametxt= (TextView) findViewById(R.id.textView66);
- Intent intent = getIntent();
- String value = intent.getStringExtra("Contacts");
- nametxt.setText(value);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_location_detail, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- public class ListDataAdapter extends ArrayAdapter {
- List list = new ArrayList();
- public ListDataAdapter(Context context, int resource) {
- super(context, resource);
- }
- static class LayoutHandler
- {
- TextView Contact,Location,Issue;
- }
- @Override
- public void add(Object object) {
- super.add(object);
- list.add(object);
- }
- @Override
- public int getCount() {
- return list.size();
- }
- @Override
- public Object getItem(int position) {
- return list.get(position);
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View row = convertView;
- LayoutHandler layoutHandler;
- if (row == null) {
- LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- row = layoutInflater.inflate(R.layout.display_product_row, parent, false);
- layoutHandler = new LayoutHandler();
- layoutHandler.Contact = (TextView) row.findViewById(R.id.textView8);
- layoutHandler.Location = (TextView) row.findViewById(R.id.textView18);
- layoutHandler.Issue = (TextView) row.findViewById(R.id.textView90);
- row.setTag(layoutHandler);
- } else {
- layoutHandler = (LayoutHandler) row.getTag();
- }
- Information information = (Information) this.getItem(position);
- layoutHandler.Contact.setText(information.getContact());
- layoutHandler.Location.setText(information.getLocation());
- layoutHandler.Issue.setText(information.getIssue());
- return row;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement