我正在制作一个应用程序,遇到了一个问题
我为谷歌地图单独制作了一个应用程序,它运行得很完美,我制作了第二个有列表视图的应用程序,通过点击列表视图中的项目,另一个活动开始了,打开了带有不同标记的谷歌地图
因此,在点击listview中的单独对象后,我设法运行了另一个活动,所以我修改了objects.xml和.java文件,原理与我在谷歌地图应用程序中所做的相同,但不知何故,它不起作用。
主活动
package com.example.e_idem;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ListActivity {
String [] usluga = {
"Frizerski salon",
"Kafić",
"Vodoinstalater",
"Bravar",
"Ljekarna",
"Pekara",
"Autoservis",
"Dućan",
"Knjižnica",
"Papirnica",
"Željezara",
"Smartshop",
"Servis bicikla"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Odaberite uslugu koju tražite.")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
TextView messageView = (TextView)alert.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usluga));
}
public void onListItemClick(ListView parent, View view, int position,long id)
{
Toast.makeText(this, "Odabrali ste uslugu : "+usluga[position], Toast.LENGTH_LONG).show();
switch( position )
{
case 0: Intent activity_frizerski_salon = new Intent(this, FrizerskiSalon.class);
startActivity(activity_frizerski_salon);
break;
case 1: Intent activity_kafic = new Intent(this, Kafic.class);
startActivity(activity_kafic);
break;
case 2: Intent activity_vodoinstalater= new Intent(this, Vodoinstalater.class);
startActivity(activity_vodoinstalater);
break;
}
}
}
我在Main_Activity中调用的活动,用于单击列表视图中的对象
package com.example.e_idem;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
public class FrizerskiSalon extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frizerski_salon);
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.fmap)).getMap();
LatLng vz = new LatLng(46.305746, 16.336606);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(vz, 13));
map.addMarker(new MarkerOptions()
.title("Varaždin")
.snippet("Barokni grad")
.position(vz));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.300274, 16.330769)));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.306274, 16.300769)));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.306974, 16.303169)));
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag_red))
.anchor(0.0f, 1.0f) // Anchors the marker on the bottom left
.position(new LatLng(46.302874, 16.400710)));
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.e_idem"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<permission
android:name="com.example.e_idem.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.e_idem.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/house_flag"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.e_idem.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="com.example.e_idem.FrizerskiSalon"
android:label="@string/activity_frizerski_salon" >
</activity>
<activity
android:name="com.example.e_idem.Kafic"
android:label="@string/activity_kafic" >
</activity>
<activity
android:name="com.example.e_idem.Vodoinstalater"
android:label="@string/activity_vodoinstalater" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCKxxxxxxxxxxxxxxxxxxVfSY_9zxmU"/>
</application>
</manifest>
还有我的LogCathttp://paste.strictfp.com/39582
您的清单文件中需要两个元数据条目:
1) 地图键
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCKxxxxxxxxxxxxxxxxxxVfSY_9zxmU"/>
2) 谷歌播放服务版本
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
您缺少第二个