I want to Preview Image beside the List using the Table Layout and Bitmap Factory.
But i am able to see only one the first image beside the list.
I am not using any XML specification, I am just write the code to set layout.
My Code is here as below.
Please tell me if any one has any idea.
If possible then also tell How to set a view in Specific cell of specific column.
Or how to set the Column number at the time of set the view to table layout.
- Code: Select all
private ViewGroup AlbumForm() {
final TableLayout parentView = new TableLayout(this);
parentView.setLayoutParams(new ViewGroup.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
parentView.setColumnStretchable(1, true);
parentView.setOrientation(TableLayout.VERTICAL);
TableRow tbl3 = new TableRow(this);
ImageView imv=new ImageView(this);
Bitmap bm = BitmapFactory.decodeFile("/dev/dog.jpg");
imv.setImageBitmap(Bitmap.createBitmap(bm));
imv.setTag("Hello");
Matrix mx = new Matrix();
mx.postScale((float) 20 / bm.getWidth(), (float) 20 / bm.getHeight());
bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mx,
true);
imv.setImageBitmap(bm);
tbl3.addView(imv);
ImageView imv1=new ImageView(this);
Bitmap bm1 = BitmapFactory.decodeFile("/dev/d4.jpg");
imv1.setImageBitmap(Bitmap.createBitmap(bm1));
imv1.setTag("Hello");
Matrix mx1 = new Matrix();
mx1.postScale((float) 20 / bm1.getWidth(), (float) 20 / bm1.getHeight());
bm1 = Bitmap.createBitmap(bm1, 0, 0, bm1.getWidth(), bm1.getHeight(), mx1,
true);
imv1.setImageBitmap(bm1);
tbl3.addView(imv1);
if (album.length > 0) {
final ListView lw = new ListView(this);
Log.i(tag, "::" + userName + "::" + password + "::");// + album);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_gallery_item, album);
lw.setAdapter(arrayAdapter);
lw.setDividerHeight(2);
lw.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Log.i(tag, "==========" + arg2 + "" + arg3);
Context contex = arg0.getContext();
Intent i = new Intent(contex, Photo.class);
i.putExtra("name", Name);
i.putExtra("number", number);
i.putExtra("userId1", userId[arg2]);
i.putExtra("auserId2", userId[arg2]);
startActivity(i);
// getPhotos(arg2);
}
});
tbl3.addView(lw);
parentView.addView(tbl3);
} else {
final TextView lblNoAlbum = new TextView(this);
lblNoAlbum.setText("No Albums");
lblNoAlbum.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f);
lblNoAlbum.setTypeface(Typeface.DEFAULT_BOLD);
}
final Button btnNew = new Button(this);
btnNew.setText("Add New Album");
btnNew.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15f);
btnNew.setTypeface(Typeface.DEFAULT_BOLD);
btnNew.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Context contex = view.getContext();
Intent i = new Intent(contex, AlbumAddPhoto.class);
i.putExtra("name", Name);
i.putExtra("number", number);
startActivity(i);
}
});
parentView.addView(btnNew);
//parentView.addView(linear1);
//parentView.addView(linear2);
ImageView im = new ImageView(this);
Bitmap bm = null;
try {
httpclient = new DefaultHttpClient();
httpost = new HttpPost(
"http://lh6.ggpht.com/calanderdemo1/SNty5JKjiOE/AAAAAAAAAhY/_3zamTg86Qw/s160-c/Album01.jpg");
response = httpclient.execute(httpost);
if (response.getStatusLine().getStatusCode() == 200) {
entity = response.getEntity();
} else {
new AlertDialog.Builder(AlbumPhoto.this).setTitle(
"Connection Error").setMessage(
"Error while connecting"
+ response.getStatusLine().getStatusCode())
.setIcon(drawable.stat_notify_error).setPositiveButton(
"ok", null).create().show();
}
if (entity != null) {
InputStream is = entity.getContent();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
}
} catch (IOException e) {
Log.e(tag, "Error getting bitmap", e);
}
Matrix mx = new Matrix();
mx.postScale((float) 50 / bm.getWidth(), (float) 50 / bm.getHeight());
bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mx,
true);
im.setImageBitmap(bm);
return parentView;
}
Thanks in Advance........


