80,351
社区成员
发帖
与我相关
我的任务
分享
ERROR/AndroidRuntime(7458): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 告诉帮忙解决一下
public class MainActivity extends Activity {
private static String TAG="MainActivity";
private Button expressionButton;
private LayoutInflater inflater;
private GridView mGridView;
private EditText et;
private Dialog dialog;
private int[]face=new int[]
{ R.drawable.smiley_b_close,R.drawable.smiley_colon_apostrophe_open,
R.drawable.smiley_colon_close,R.drawable.smiley_colon_d,
R.drawable.smiley_colon_dollar,R.drawable.smiley_colon_e,
R.drawable.smiley_colon_o,R.drawable.smiley_colon_open,
R.drawable.smiley_colon_p,R.drawable.smiley_colon_pipe,
R.drawable.smiley_colon_s,R.drawable.smiley_colon_slash,
R.drawable.smiley_colon_star,R.drawable.smiley_colon_three,
R.drawable.smiley_colon_x,R.drawable.smiley_greater_than_colon_open,
R.drawable.smiley_kik,R.drawable.smiley_less_than_slash_three,
R.drawable.smiley_less_than_three,R.drawable.smiley_semicolon_close
};
private ImageGetter imageGetter = new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
int id = Integer.parseInt(source);
Drawable draw = getResources().getDrawable(id);
draw.setBounds(0, 0, draw.getIntrinsicWidth(), draw.getIntrinsicHeight());
return draw;
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText) findViewById(R.id.EditText1);
expressionButton = (Button) findViewById(R.id.expressionButton);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.customdialog, null);
mGridView = (GridView) layout.findViewById(R.id.gridview);
mGridView.setAdapter(new ImageAdapter(MainActivity.this));
expressionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// MyDialog myDialog = new MyDialog(MainActivity.this);
// myDialog.show();
dialog =new Dialog(MainActivity.this);
dialog.setContentView(mGridView);
dialog.setTitle("表情选择");
dialog.show();
}
});
mGridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
alertFace(position);
}
public void alertFace(int position) {
et.append(Html.fromHtml("<img src='"+face[position]+"'/>",imageGetter,null));
//e_text = et.getText().toString();
dialog.dismiss();
}
});
}
@Override
protected void onStart() {
super.onStart();
}
}