I am using intent to call another activity and passing the listview's value to the second activity but getting error on click on the listview selection. Getting
Below is my MainActivity
package com.listview_gps;
public class MainActivity extends ListActivity {
String [] locations = {
"KFC",
"McDonalds",
"A & W",
"Burger King",
"Tesco",
"Home"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, locations));
}
public void onListItemClick(
ListView parent, View v, int position, long id)
{
Intent intent = new Intent(MainActivity.this, location_gps.class);
intent.putExtra("Location", locations[position].toString());
startActivity(intent);
}
My Second Activity
Package com.listview_gps;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class location_gps extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locationgps);
TextView nameView = (TextView) findViewById(R.id.locationgps);
nameView.setText(getIntent().getExtras().getString("Location"));
}
}
My Manifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.listview_gps.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name = ".location_gps"
android:label="Location GPS" >
<intent-filter>
<action android:name = "com.listview_gps" />
<category android:name = "android.intent.category.DEFAULT" />
</intent-filter>
></activity>
</application>
</manifest>