i want to dynamically add images and textviews from database (blue on the picture). I also want it to be clickable, and that it could pass it's Id or something to the next activity. I thought of listview, but eclipse says it shouldn't be in a scrollview. So I tried creating linear layout, and inside it I tried to put another linear layouts (different orientation) containing image and textview (so like one linear layout per row). I'm not sure if I did it ok, but it only displays first image and last textview, so i guess it's not the right way.
Here's the layout image: http://pbrd.co/R0JVKs
Here's how I add the views:
//architekti
llArchitekti = (LinearLayout) findViewById(R.id.architekt_layout);
LinearLayout llArchitekt;
ImageView arch_obr;
TextView tvArchitekt;
int i = 0;
for(String architekt : architekti){
arch_obr = new ImageView(ObjectInfo.this);
if(architekti_obrazky.size()>i && architekti_obrazky.get(i)!="no_image"){
arch_obr.setImageBitmap(BitmapFactory.decodeFile(getExternalFilesDir(null)+"/images/thumb/obr_"+architekti_obrazky.get(i)+"_1.jpg"));
}else{
arch_obr.setImageBitmap(BitmapFactory.decodeFile(getExternalFilesDir(null)+"/images/thumb/no_image.jpg"));
}
arch_obr.setPadding(8, 8, 20, 8);
arch_obr.setLayoutParams(new LayoutParams( 150 , LayoutParams.WRAP_CONTENT));
//here starts the adding part
llArchitekt = new LinearLayout(ObjectInfo.this);
llArchitekt.setOrientation(LinearLayout.VERTICAL);
llArchitekt.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
tvArchitekt = new TextView(ObjectInfo.this);
tvArchitekt.setText(architekt);
tvArchitekt.setClickable(true);
tvArchitekt.setTextSize(22);
tvArchitekt.setPadding(8, 8, 20, 8);
tvArchitekt.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
llArchitekt.addView(arch_obr);
llArchitekt.addView(tvArchitekt);
llArchitekti.addView(llArchitekt);
i++;
}
llArchitekt should be linear layout for each row, llArchitekti should be the linear layout that I add rows to.
llArchitekt - vertical llArchitekti - horizontal
Also I'm not sure if it's possible to get some ID (ideally the one from database) from it on click.
You should use a ListView with Custom Adapter. There are many tutorials on the web:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.