Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ListView listview;
- ArrayList<String> arrayList;
- ArrayAdapter<String> arrayAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
- }
- arrayList = new ArrayList<String>();
- arrayList.add("Add new place...");
- listview = (ListView) findViewById(R.id.listView);
- arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);
- listview.setAdapter(arrayAdapter);
- }
- @Override
- protected void onStart() {
- super.onStart();
- boolean startedFromIntent;
- Intent i = getIntent();
- if (i.getIntExtra(getString(R.string.starting_from_intent), 0) == 5) {
- startedFromIntent = true;
- } else {
- startedFromIntent = false;
- }
- if(startedFromIntent && i.getStringExtra("address") != null) {
- arrayList.add(i.getStringExtra("address"));
- arrayAdapter.notifyDataSetChanged();
- }
- listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
- Intent intent = new Intent(getApplicationContext(), MapsActivity.class);
- intent.putExtra("placeNumber", i);
- startActivity(intent);
- }
- });
- }
Add Comment
Please, Sign In to add comment