任何想法如何啓動一個活動並從對話框按鈕發送一個值?如何從對話框中啓動活動?
這就是我目前所擁有的。嘗試了許多變化,但應用程序崩潰時按下按鈕:
dialog.setPositiveButton("View Profile", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setClass(context, Profile.class);
intent.putExtra("profileID", "8");
startActivity(intent);
dialog.cancel();
return;
}
});
滿級:
public class PlacesItemizedOverlay extends ItemizedOverlay {
private Context context;
private ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
private Activity aClass;
public PlacesItemizedOverlay(Context aContext, Drawable marker) {
super(boundCenterBottom(marker));
context = aContext;
}
public void addOverlayItem(OverlayItem item) {
items.add(item);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return (OverlayItem) items.get(i);
}
@Override
public int size() {
return items.size();
}
@Override
protected boolean onTap(int index) {
aClass = new Activity();
OverlayItem item = (OverlayItem) items.get(index);
if(item.getTitle() != null)
{
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(item.getTitle());
dialog.setPositiveButton("View Profile",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setClass(context, Profile.class);
intent.putExtra("profileID", "8");
aClass.startActivity(intent);
dialog.cancel();
return;
}
});
dialog.show();
}
return true;
}
}
的logcat:
06-24 10:35:31.253: WARN/dalvikvm(30118): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): FATAL EXCEPTION: main
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): java.lang.NullPointerException
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at android.app.Activity.startActivityForResult(Activity.java:2901)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at android.app.Activity.startActivity(Activity.java:3007)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at com.example.android.test.PlacesItemizedOverlay$1.onClick(PlacesItemizedOverlay.java:57)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at android.os.Looper.loop(Looper.java:143)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at android.app.ActivityThread.main(ActivityThread.java:4196)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at java.lang.reflect.Method.invoke(Method.java:507)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-24 10:35:31.283: ERROR/AndroidRuntime(30118): at dalvik.system.NativeStart.main(Native Method)
06-24 10:35:31.293: WARN/ActivityManager(1344): Force finishing activity com.example.android.test/.SearchActivity
'putExtra ()'是正確的使用方法。堆棧跟蹤中的錯誤消息是什麼? – Haphazard
你將不得不裸露在我身邊Haphazard,我還沒有用它來調試。我會看看是否可以找到'堆棧跟蹤'併發布。非常感謝。 – Paul
在命令窗口中鍵入'adb logcat'並查找大錯誤消息。 – Haphazard