Я пытаюсь получить класс, расширяющий ItemizedOverlay до startActivity, но есть проблема, он просто не будет компилироваться. У меня есть MapView, который использует класс ItemizedOverlay для рисования наложений, но я хочу начать и активность, когда я нажимаю на экран.
Есть идеи, как решить эту проблему? Благодаря
protected boolean onTap(int index) {
OverlayItem item = overlays.get(index);
String split_items = item.getSnippet();
Intent intent = new Intent();
intent.setClass(mainmenu,poiview.class);
startActivity(intent);
return true;
}
У меня была эта проблема, поэтому я проверил пример ниже. Решение зависит от вызова "startActivity" из контекста MapActivity.
Если ваша карта действительно работает с оверлеями, вы уже передали контекст MapView в свой собственный конструктор ItemizedOverlay, и вам, вероятно, присвоен контекст MapView переменной класса mContext (я делаю предположения, что вы следовали примеру Google MapView), Поэтому в вашей пользовательской функции Overlay onTap выполните следующее:
@Override
protected boolean onTap(int index) {
Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
mContext.startActivity(intent);
return true;
}
Но вы, вероятно, захотите передать что-то новому мероприятию, которое вы пытаетесь запустить, чтобы ваша новая деятельность могла сделать что-то полезное с вашим выбором. Так что...
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
//assumption: you decided to store an "id" in the snippet so you can associate this map location with your new Activity
long id = Long.parseLong(item.getSnippet()); //Snippet is a built-in String property of an Overlay object.
//pass an "id" to the class so you can query
Intent intent = new Intent(mContext, ActivityYouAreTryingToLaunch.class);
String action = Intent.ACTION_PICK; //You can substitute with any action that is relevant to the class you are calling
//I create a URI this way because I append the id to the end of the URI (lookup the NotePad example for help because there are many ways to build a URI)
Uri uri = ContentUris.withAppendedId(Your_CONTENT_URI, id);
//set the action and data for this Intent
intent.setAction(action);
intent.setData(uri);
//call the class
mContext.startActivity(intent);
return true;
}
Попробуйте это, я сделал это, установив положительную кнопку в диалоговом окне предупреждения...
protected boolean onTap(int index) {
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setIcon(R.drawable.info_icon);
dialog.setPositiveButton("Details", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent placeDetailsMapIntent = new Intent(mContext, PlaceDetailsActivity.class);
mContext.startActivity(placeDetailsMapIntent);
}
});
попробуйте использовать следующие
Intent intent = new Intent(mainmenu.this, poview.class);
startActivity(intent);