0

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>
4

1 回答 1

0

类名应以大写字母开头,因此将您的类名 location_gps 更改为 Location_gps 并确保在清单内的每个位置也进行更改

于 2013-08-14T08:14:07.353 回答