我有一个带有 itemizedoverlays 的地图视图,就像在 android 开发人员指南的示例中一样:http: //developer.android.com/resources/tutorials/views/hello-mapview.html
在 itemizedoverlay 上,我有一个带有按钮的个性化对话框。一切都很好,直到这里,但现在我在尝试将功能添加到按钮时遇到问题。我需要按钮开始是一项新活动,但我无法实现.... ¿为什么?因为在这一行上:i = new Intent (NyItemizedOverlay.class, Locate.class);
我将当前 Intent 类作为第一个参数,将目标 Intent 类作为第二个参数。
MyItemizedOverlay 不是 Intent 类...它是 ItemizedOverlay 扩展,然后当我尝试启动意图时它不会编译,我试图将普通类作为第一个参数传递,它需要一个意图类。我必须放置启动器类,但启动器类不是意图: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;
}
}