2011-08-28
My first android app ---- happy first version is coming soon
This week, the computation has done something and added icons and pic for the result page.
To sum up
Problem: add an image for AlertDialog. The number of images is displayed based on the number of result objects.
Check AlertDialog sdk and find that a better way is to create FrameLayout, add imageview to it, and set it to the dialog attribute.
However, how to create FrameLayout does take some twists and turns out, And framelayout cannot be added to layout of the same activity.
The specified child all ready has a parent error may occur.
You need to create a new propalterdialog. xml to define it separately and place layout, and then call LayoutInflater to change the layout to the current layout display.
The ImageView label can be defined in FrameLayout xml.
Use framelayout context to dynamically generate an image
However, the image in framelayout overlaps. When LinearLayout is used, android: orientation = "horizontal" is set in the xml file, and the image is placed in one row.
The following are all the codes used.
LayoutInflater factory = LayoutInflater.from(DemoActivity.this);
LinearLayout fl = (LinearLayout) factory.inflate(R.layout.propalterdialog,null);
int size = selectionList.size();
for(Selection sel:selectionList){
ImageView imageView = new ImageView(fl.getContext());
imageView.setLayoutParams(new FrameLayout.LayoutParams(190/size, 190/size, 100));
int image_id = DemoActivity.this.getResources().getIdentifier(sel.getPicture(), "drawable",
"com.netqin.android.lab");
imageView.setImageResource(image_id);
fl.addView(imageView);
}
new AlertDialog.Builder(DemoActivity.this).setTitle("result")
.setIcon(R.drawable.result_icon)
.setView(fl)
.setMessage(result).setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}