내가 itemizedoverlays와지도보기을 가지고, 상기 itemizedoverlay에 http://developer.android.com/resources/tutorials/views/hello-mapview.htmlItemizedOverlay 클래스에서 인 텐트를 시작할 수 있습니까? 정확히 안드로이드 개발자 가이드의 예에서와 같은 (지도보기 항목)
, 나는 버튼과, 개인 대화가있다. 여기까지는 괜찮지 만 버튼에 기능을 추가하는 데 문제가 있습니다. 버튼 시작은 새로운 활동이 필요하지만, 나는 그것을 달성 할 수 없습니다 .... ¿ 이유는 무엇입니까? 왜냐하면이 줄에서 : i = new Intent (NyItemizedOverlay.class, Locate.class);
나는 현재 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;
}
}
해결! 고마워. – NullPointerException