我有一個MapView,與itemizedoverlays,酷似在Android開發者指南的例子:http://developer.android.com/resources/tutorials/views/hello-mapview.html可以從ItemizedOverlay類開始一個Intent嗎? (MapView類項目)
在itemizedoverlay,我有一個個性化的對話,一個按鈕。所有罰款直到這裏,但現在我有問題試圖添加功能的按鈕。我需要按鈕開始一個新的活動,但我無法實現....¿爲什麼?因爲在這一行:i = new Intent (NyItemizedOverlay.class, Locate.class);
我有當前的Intent類作爲第一個參數,目標意圖類在第二個參數。
MyItemizedOverlay不是一個Intent類...它是ItemizedOverlay擴展,然後當我嘗試啓動intent時,它不編譯,我試圖傳遞一個普通類作爲第一個參數,並且它需要一個intent類。我必須把發射器類,但發射器類不是一個意圖:S
如果我試圖把第一個參數的另一個意圖類,我得到這個錯誤:No enclosing instance of the type AllActivity is accessible in scope
....(AllActivity是一個公共我的應用程序的活動類)
我該如何解決這個問題?
完整的代碼在這裏:
public class MyItemizedOverlay extends ItemizedOverlay {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private ArrayList<String> permissions = new ArrayList<String>();
private Context mContext;
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
public int size() {
return mOverlays.size();
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
public void addOverlay(OverlayItem overlay,String permission) {
mOverlays.add(overlay);
permissions.add(permission);
populate();
}
public MyItemizedOverlay(Drawable defaultMarker, Context context) {
//super(defaultMarker);
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void clear()
{
mOverlays.clear();
permissions.clear();//lista de permisos de cada usuario, ya que hay dos campos, el email (snippet) y el permission, una lista.
}
protected boolean onTap(int index) {
try{
OverlayItem item = mOverlays.get(index);
if (permissions.size()==0)
{
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
}
else
{
//set up dialog
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.personal_dialog);
dialog.setTitle(item.getTitle());
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
//set up text
TextView DialogEmail = (TextView) dialog.findViewById(R.id.DialogEmail);
TextView DialogPermission = (TextView) dialog.findViewById(R.id.DialogPermission);
DialogEmail.setText(item.getSnippet());
DialogPermission.setText(permissions.get(index));
final String userName=item.getTitle();
final String email=item.getSnippet();
final int cont=index;
//set up button
Button button = (Button) dialog.findViewById(R.id.DialogButton);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//do something
Bundle bundle = new Bundle(); //bundle is like the letter
bundle.putString ("user",userName); //arg1 is the keyword of the txt, arg2 is the txt
bundle.putString ("email", email);
bundle.putString ("permission", permissions.get(cont));
Intent i=null;
i = new Intent (MyItemizedOverlay.class, Locate.class);
i.putExtras(bundle);
startActivity(i);
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
}
}catch(Exception e){}
return true;
}
}
解決!非常感謝 – NullPointerException 2010-12-15 14:49:05