I am new to building android apps and I've been trying to open a new activity from a row in a list where each activity displays google map of each row. So far I have managed to open a new activity by clicking the row, but I have no idea how to insert Google map on them. I have downloaded my Google api key and saved it on my AndroidManifest.
My code looks looks like this that opens the list:
package com.MaheshGurung.androidapp;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class secondActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// storing string resources into Array
String []Buildings = getResources().getStringArray(R.array.Buildings);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.screen1, R.id.listbuilding, Buildings));
}
protected void onListItemClick(ListView lv, View v, int position, long id){
super.onListItemClick(lv, v, position, id);
Intent intent = new Intent();
intent.setClass(this, ListSelect.class);
intent.putExtra("position", position);
// Or / And
intent.putExtra("id", id);
startActivity(intent);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
And the code which opens new activity for each row looks like this:
package com.MaheshGurung.androidapp;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class secondActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// storing string resources into Array
String []Buildings = getResources().getStringArray(R.array.Buildings);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.screen1, R.id.listbuilding, Buildings));
}
protected void onListItemClick(ListView lv, View v, int position, long id){
super.onListItemClick(lv, v, position, id);
Intent intent = new Intent();
intent.setClass(this, ListSelect.class);
intent.putExtra("position", position);
// Or / And
intent.putExtra("id", id);
startActivity(intent);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
and .xml file looks like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_textview"/>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@+id/my_textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
It would be very helpful to know where to write code for google map or any other suggested method.