adeen-s

memorable places

Jul 27th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1.     ListView listview;
  2.     ArrayList<String> arrayList;
  3.     ArrayAdapter<String> arrayAdapter;
  4.  
  5.     @Override
  6.     protected void onCreate(Bundle savedInstanceState) {
  7.         super.onCreate(savedInstanceState);
  8.         setContentView(R.layout.activity_main);
  9.  
  10.         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  11.             ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
  12.         }
  13.  
  14.         arrayList = new ArrayList<String>();
  15.         arrayList.add("Add new place...");
  16.  
  17.         listview = (ListView) findViewById(R.id.listView);
  18.         arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);
  19.         listview.setAdapter(arrayAdapter);
  20.     }
  21.  
  22.     @Override
  23.     protected void onStart() {
  24.         super.onStart();
  25.        
  26.         boolean startedFromIntent;
  27.  
  28.         Intent i = getIntent();
  29.         if (i.getIntExtra(getString(R.string.starting_from_intent), 0) == 5) {
  30.             startedFromIntent = true;
  31.         } else {
  32.             startedFromIntent = false;
  33.         }
  34.  
  35.         if(startedFromIntent && i.getStringExtra("address") != null) {
  36.             arrayList.add(i.getStringExtra("address"));
  37.             arrayAdapter.notifyDataSetChanged();
  38.         }
  39.  
  40.         listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  41.             @Override
  42.             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  43.                 Intent intent = new Intent(getApplicationContext(), MapsActivity.class);
  44.                 intent.putExtra("placeNumber", i);
  45.                 startActivity(intent);
  46.             }
  47.         });
  48.     }
Add Comment
Please, Sign In to add comment