我正在使用意图调用另一个活动并将listview的值传递给第二个活动但是在单击列表视图选择时收到错误。获得
以下是我的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);
}
我的第二项活动
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"));
}
}
我的清单
<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>
答案 0 :(得分:0)
班级名称应以大写字母开头,因此请将您的班级名称location_gps更改为Location_gps,并确保在清单内的每个位置都进行更改