0
메신저 내 기본 클래스보다 별도의 클래스에서 내 alertdialog 만들려고하고 그것도 가져옵니다 및 오류 및 응용 프로그램이 중지되면, 내가 어떻게 예외를 catch 할 것이라고 알고 싶습니다 또는 오류를 찾을 수있는 방법 이런 코드. 여기 AlertDialog를 사용할 때 예외를 잡기?
이 경고 대화 상자에 대한 코드입니다 : 여기import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class PlacepinDialog extends AlertDialog{
AlertDialog.Builder builder;
AlertDialog alertDialog;
TextView text;
ImageView image;
Button place;
Button cancel;
LayoutInflater inflater;
View layout;
public PlacepinDialog(Context context) {
super(context);
//Setting up View and Inflater
LayoutInflater inflater = (LayoutInflater)getLayoutInflater();
View layout = inflater.inflate(R.layout.placepin_dialog,
(ViewGroup) findViewById(R.id.mvMain));
//Text Views
TextView text = (TextView) layout.findViewById(R.id.Placetext);
text.setText("Do you want to place a pin at the location you pressed?");
//Image Views
ImageView image = (ImageView) layout.findViewById(R.id.Placeimage);
image.setImageResource(R.drawable.icon);
//Building the Dialog
builder = new AlertDialog.Builder(context);
builder.setView(layout);
alertDialog.setTitle("Place Pin");
alertDialog = builder.create();
}
}
가에 AlertDialog가 호출된다 (이 onTouchEvent는 메인 클래스보다 다른 클래스에 그래서 난 그냥 main.this 할 수 없습니다)
public boolean onTouchEvent(MotionEvent e, MapView mv){
int i = e.getAction();
switch(i){
case MotionEvent.ACTION_DOWN:
//When your finger touches the screen
Log.d("ACTION DOWN", "Finger touched screen");
break;
case MotionEvent.ACTION_UP:
//When your finger stop touching the screen
Log.d("ACTION UP", "Finger was removed from screen");
try{
PlacepinDialog alertDialog = new PlacepinDialog(null);
}
catch(){
}
break;
case MotionEvent.ACTION_MOVE:
//When your finger moves around the screen
Log.d("ACTION MOVE", "Finger was moved around the screen");
break;
}
return false;
}
어떤 컨텍스트가 좋을까요? 나는 또한 안드로이드 컨텍스트에 관한 모든 것을 잘 읽어야합니다. – Rakso
활동의 컨텍스트를 전달해야합니다. MyActivity.this일지도 모른다. –
이 컨텍스트에 대해 알 수있는 링크 나 페이지를 알고 있습니까? Cus 나는 그것이 어떻게 작동하는지 전혀 모른다. 그리고 클래스에서 대화창은 아무런 문맥도 만들어지지 않았다고 불린다. – Rakso