Dialog에 이미지 하나를 넣을려고 하는데 안되네요.
주요 에러는 다음과 같습니다.
The specified child already has a parent. You must call removeView() on the child's parent first;
LayoutInflater layout2=((Activity) mContext).getLayoutInflater();
ImageSelection is=new ImageSelection(mContext);
View v=is.getImageView();
Dialog da=new AlertDialog.Builder(mContext)
.setIcon(R.drawable.androidmarker)
.setTitle("이미지")
.setMessage("이미지 아이콘")
.setPositiveButton("11", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d("?>_<",">_;< ㅠ");
}
})
.setView(v)
.create();
da.show();
여기서 ImageSelection의 클래스는 다음과 같습니다.
public class ImageSelection implements android.view.View.OnClickListener{
private Context mContext;
LinearLayout v;
ImageButton ib2;
public ImageSelection(Context mcontext) {
mContext=mcontext;
Layout();
}
public void Layout() {
LinearLayout root=new LinearLayout(mContext);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT,0.0f);
root.setLayoutParams(params);
root.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams tvParams2=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,0.0f);
ImageButton ib=new ImageButton(mContext);
Bitmap orgImage=BitmapFactory.decodeResource(mContext.getResources(),R.drawable.help_focused);
ib.setImageBitmap(orgImage);
ib.setLayoutParams(tvParams2);
ib.setId(1);
ib2=ib;
root.addView(ib);
ib.setOnClickListener(this);
v=root;
((Activity) mContext).setContentView(root);
}
@Override
public void onClick(View v) {
if(v.getId()==1){
Log.d("true","true");
}
}
public View getView(){
return v;
}
public View getImageView(){
return ib2;
}
}
에러는 이렇게 뜨네요.
사진 파일첨부했습니다.
왜 이런지 해답좀 부탁드릴께요. ㅠ