SHARE
TWEET

Untitled

a guest Oct 10th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.delimasqlite.myapplication;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5.  
  6. import android.os.Bundle;
  7.  
  8. import android.view.KeyEvent;
  9. import android.view.Menu;
  10. import android.view.MenuItem;
  11. import android.view.View;
  12.  
  13. import android.widget.AdapterView;
  14. import android.widget.ArrayAdapter;
  15. import android.widget.AdapterView.OnItemClickListener;
  16. import android.widget.ListView;
  17.  
  18. import androidx.appcompat.app.AppCompatActivity;
  19.  
  20.  
  21. import java.util.ArrayList;
  22. import java.util.List;
  23.  
  24. public class MainActivity extends AppCompatActivity {
  25.     public final static String EXTRA_MESSAGE = "MESSAGE";
  26.     private ListView obj;
  27.     DBHelper mydb;
  28.  
  29.     @Override
  30.     protected void onCreate(Bundle savedInstanceState) {
  31.         super.onCreate(savedInstanceState);
  32.         setContentView(R.layout.activity_main);
  33.  
  34.         mydb = new DBHelper(this);
  35.         ArrayList array_list = mydb.getAllCotacts();
  36.         ArrayAdapter arrayAdapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list);
  37.  
  38.         obj = (ListView)findViewById(R.id.listView1);
  39.         obj.setAdapter(arrayAdapter);
  40.         obj.setOnItemClickListener(new OnItemClickListener(){
  41.             @Override
  42.             public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
  43.                 // TODO Auto-generated method stub
  44.                 int id_To_Search = arg2 + 1;
  45.  
  46.                 Bundle dataBundle = new Bundle();
  47.                 dataBundle.putInt("id", id_To_Search);
  48.  
  49.                 Intent intent = new Intent(getApplicationContext(),DisplayContact.class);
  50.  
  51.                 intent.putExtras(dataBundle);
  52.                 startActivity(intent);
  53.             }
  54.         });
  55.     }
  56.  
  57.     @Override
  58.     public boolean onCreateOptionsMenu(Menu menu) {
  59.         // Inflate the menu; this adds items to the action bar if it is present.
  60.         getMenuInflater().inflate(R.menu.main_menu, menu);
  61.         return true;
  62.     }
  63.  
  64.     @Override
  65.     public boolean onOptionsItemSelected(MenuItem item){
  66.         super.onOptionsItemSelected(item);
  67.  
  68.         switch(item.getItemId()) {
  69.             case R.id.item1:Bundle dataBundle = new Bundle();
  70.                 dataBundle.putInt("id", 0);
  71.  
  72.                 Intent intent = new Intent(getApplicationContext(),DisplayContact.class);
  73.                 intent.putExtras(dataBundle);
  74.  
  75.                 startActivity(intent);
  76.                 return true;
  77.             default:
  78.                 return super.onOptionsItemSelected(item);
  79.         }
  80.     }
  81.  
  82.     public boolean onKeyDown(int keycode, KeyEvent event) {
  83.         if (keycode == KeyEvent.KEYCODE_BACK) {
  84.             moveTaskToBack(true);
  85.         }
  86.         return super.onKeyDown(keycode, event);
  87.     }
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top