Android ImageView dynamic width and height - android

I have a horizontal list of images loaded from a url. So i have an ImageLoader, then an Adapter then my Activity. My xml layouts looks like this:
mainlayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/hlist_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="always" >
</com.devsmart.android.ui.HorizontalListView>
</LinearLayout>
Then my list.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:translationY="200dp" > <!-- make this dynamic -->
<FrameLayout
android:id="#+id/mainlayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<ImageView
android:id="#+id/prof_pic"
android:clickable="true"
android:adjustViewBounds="true"
android:layout_width="360dp"
android:layout_height="360dp" />
<ProgressBar
android:id="#+id/img_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<TextView
android:id="#+id/sname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />
<TextView
android:id="#+id/sdesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
With this layout, the result is Figure A. The gray broken line is the imageView, we can't actually see it but only those images(green box). What i want to achieve is the one in Figure B.
So, to somewhat solve this i tried adding in my imageView
<ImageView
android:id="#+id/prof_pic"
android:clickable="true"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="360dp"
android:maxHeight="360dp"
android:minHeight="240dp"
android:minWidth="240dp"
/>
But what happened is that, by the time i open the application, my image list looks like Figure A. But when a scroll along the images, it adjusted to somewhat look like Figure B. But when i scroll back to the first image, only the first have of the image will only be show or sometimes, my image list starts at my second image. This is really crazy.
Is there any way where i can achieve Figure B without destroying my list of images or at the start of the app, it already displays like Figure B?
EDIT:
This is how my Adapter looks like:
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if(convertView == null){
convertView = inflater.inflate(R.layout.list_layout, null);
holder = new ViewHolder();
holder.txtShopName = (TextView) convertView.findViewById(R.id.shop_name);
holder.txtDesc = (TextView) convertView.findViewById(R.id.desc);
holder.imageView = (ImageView) convertView.findViewById(R.id.prof_pic);
holder.progBar = (ProgressBar) convertView.findViewById(R.id.img_progress);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
imageLoader=new ImageLoader(context.getApplicationContext(), holder.progBar);
SRowItem sItem = (SRowItem) getItem(position);
holder.txtName.setText(sItem.getShopName());
holder.txtDesc.setText(sItem.getShopDesc());
imageLoader.DisplayImage(sItem.getImageUrl(), holder.imageView);
return convertView;
}

Try something like this :
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
ImageView imageView = (ImageView) LayoutInflater.from(context).inflate(R.layout.image, null);
imageView.setLayoutParams(params);

Related

Reset TextView position in row of Listview for Android Application

I am using ListView to display some data. The data is shown in TextView. String length which is shown can vary. so the textview which is shown changes its positions depending upon the length of the string. The problem I am facing is
Suppose there are 5 rows. For Row 3 if the text is long, the position of textview showing the text adjusts to show the content. However, textview positions of other rows also changes even if the text is smaller. This has something to do with ListView row caching I am not able to figure out how to reset the row.
Row Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="#dimen/text_margin_bottom"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id1"
android:textSize="#dimen/textsize_content3" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id2"
android:textSize="#dimen/textsize_content3" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="#dimen/text_margin_bottom"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id3"
android:textSize="#dimen/textsize_content3" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id4"
android:textSize="#dimen/textsize_content3" />
</LinearLayout>
</LinearLayout>
GetView Code
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
ShowData metaData = getItem(position);
if (convertView == null) {
convertView = inflater.inflate(R.layout.row, parent, false);
holder = new ViewHolder();
holder.id1 = (TextView) convertView
.findViewById(R.id.id1);
holder.id2 = (TextView) convertView
.findViewById(R.id.id2);
holder.id3 = (TextView) convertView
.findViewById(R.id.id3);
holder.id3 = (TextView) convertView
.findViewById(R.id.id4);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
convertView.invalidate();
holder.id1.setText(metaData.id1);
holder.id2.setText(metaData.id2);
holder.id3.setText(metaData.id3);
holder.id4.setText(metaData.id4);
return convertView;
}
How to reset the listview row?
As you mentioned, your TextViews are sizing vertically due to the wrap_content values for their layout_heights. It seems that when Views are recycled in ListViews (and, most likely, all AdapterViews), no layout is automatically triggered, so the TextViews will retain their previous heights. Calling requestLayout() on them will trigger a layout event, during which the TextViews will adjust to their new contents.

Multiple Clickable Areas in ListItem

I have a list that is organized as follows:
CheckBox,
ImageButton,
LinearLayout{ TextView title, TextView Subtitle}
What I am trying to do is to have three separate clickable areas of the ListItem: the checkbox should be checkable, ImageButton, and the actual list item itself. The checkbox is hidden by default, but can be made visible when a certain button on the list's header is pressed (ie SELECT). I just want a way to select multiple items from the list, and I am not irreversibly set on using hidden checkboxes- if there is a way to do this that would be easier, I would be happy to hear the alternative.
Here is the relevant snippet of my adapter:
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
final T t = list.get(position);
if(convertView == null){
convertView = vi.inflate(R.layout.folder_list_item,parent,false);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.text_view_folder_item);
holder.subtitle = (TextView) convertView.findViewById(R.id.text_view2);
holder.eye = (ImageButton) convertView.findViewById(R.id.folder_vis_button);
holder.check = (CheckBox) convertView.findViewById(R.id.phone);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(t.getName());
holder.subtitle.setText(t.getDescription());// = (TextView) convertView.findViewById(R.id.text_view2);
return convertView;
}
And the XML is as follows. As you can see, I have made the individual list items clickable but unfocassable, as recommended in posts I have read about this very problem.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true">
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:visibility="invisible"
android:focusable="false"/>
<ImageButton
android:id="#+id/folder_vis_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:layout_toRightOf="#+id/checkbox"
android:contentDescription="#string/contentDescription"
android:focusable="false"
android:src="#drawable/open_eyeball" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_toRightOf="#id/folder_vis_button"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
android:focusable="false"
android:clickable="true">
<TextView
android:id="#+id/text_view_folder_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/text_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Clicking on the list item is handled, if I convert the listitem to actually use on of the built in listitems such as android.R.layout.simple_list_item_1.
However, when I use my own layout, I cannot get click events on the list item itself, just on the image button.
I have tried inflating the view in a different way (int resource, ViewGroup root) ... I have tried working just with the imagebutton, or just with the checkbox, using an imageview instead of an imagebutton, with little in terms of success. Thank you for taking the time to look at this.

Create custom ListView with shadow

How could I create custom ListView like shown in this picture. I know I can make this happen with help of ScrollView and Layouts, but I need to do as a ListView.
Each listview item go over each other.
This may help you
List view with custom view items with partially overlaps (Android)
I have this code like your Requirement. List may overlap by reducing the dividerheight to minus value
<?xml version="1.0" encoding="utf-8"?>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="-5dp"
android:listSelector="#drawable/list_selector" />
Then add background color to adapter according to the position.
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView)vi.findViewById(R.id.title); // title
TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
HashMap<String, String> song = new HashMap<String, String>();
if(position % 2 ==0){
vi.setBackgroundResource(R.drawable.listselector_1);
}else if(position % 3 ==0){
vi.setBackgroundResource(R.drawable.listselector_2);
}else{
vi.setBackgroundResource(R.drawable.listselector_3);
}
song = data.get(position);
// Setting all values in listview
title.setText(song.get(CustomizedListView.KEY_TITLE));
artist.setText(song.get(CustomizedListView.KEY_ARTIST));
duration.setText(song.get(CustomizedListView.KEY_DURATION));
imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
return vi;
}
Otherwise you can use listselector images also as your requirement
Thank you guys for trying help me to solve this issue. I look every answer here and finally get i want. I think it will be better I put my code here so maybe someone it will be helpful. The only difference is that my created listview has also shadow in it.
Here is the code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:my_font="http://schemas.android.com/apk/res/com.Helix.android.SmartBonus"
android:orientation="vertical"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
>
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shadow_bg"
android:visibility="visible"/>
<RelativeLayout
android:id="#+id/secondLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#drawable/drop_shadow"
android:layout_below="#id/imageview">
<ImageView
android:id="#+id/companyImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/secret_logo_small"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/companyDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/companyImageView"
android:textColor="#android:color/white"
android:layout_marginTop="7dp"
my_font:ttf_name="300"
android:text="Салон кросаты"/>
<TextView
android:id="#+id/companyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/companyImageView"
android:layout_below="#id/companyDescription"
android:textColor="#android:color/white"
my_font:ttf_name="300"
android:text="Secret"/>
<TextView
android:id="#+id/companyPercentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_marginTop="7dp"
android:textSize="19sp"
android:layout_marginRight="1dp"
android:layout_toLeftOf="#+id/companyPercent"
my_font:ttf_name="700"
android:text="-20"/>
<TextView
android:id="#id/companyPercent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#android:color/white"
android:layout_marginTop="7dp"
android:textSize="12sp"
my_font:ttf_name="300"
android:text="%"/>
<ImageView
android:id="#+id/companyPercentImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/companyPercent"
android:layout_marginTop="7dp"
android:textColor="#android:color/white"
android:src="#drawable/percentage_devider"/>
<TextView
android:id="#+id/companyDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/companyPercentImage"
android:textSize="16dp"
android:textColor="#A57F1C"
my_font:ttf_name="300"
android:text="7m"/>
<LinearLayout
android:id="#+id/checkingButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/companyDistance"
android:layout_marginTop="10dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:focusable="false"
android:background="#drawable/green_button_bg"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="16dp"
android:textColor="#android:color/white"
my_font:ttf_name="300"
android:text="Check-in"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="16dp"
android:layout_marginLeft="10dp"
android:textColor="#color/checkin_point_color"
android:layout_weight="1"
my_font:ttf_name="300"
android:text="#string/ten_point"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/slak"
/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
adapter.
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
final Discount discount = getItem(i);
Discount prev_discount = null;
if (i > 0){
prev_discount = getItem(i-1);
}
if (view == null){
final LayoutInflater li = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.discount_data_item, viewGroup, false);
viewHolder = new ViewHolder();
viewHolder.logo = (ImageView)view.findViewById(R.id.companyImageView);
viewHolder.name = (SmartBonus_TextView)view.findViewById(R.id.companyName);
viewHolder.description = (SmartBonus_TextView)view.findViewById(R.id.companyDescription);
viewHolder.percent = (SmartBonus_TextView)view.findViewById(R.id.companyPercentText);
viewHolder.distance = (SmartBonus_TextView)view.findViewById(R.id.companyDistance);
viewHolder.mainLayout = (RelativeLayout)view.findViewById(R.id.mainLayout);
viewHolder.secondLayaout = (RelativeLayout)view.findViewById(R.id.secondLayout);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
if (i == 0){
viewHolder.mainLayout.setBackgroundColor(android.R.color.transparent);
setRoundedBackground(viewHolder.secondLayaout, Color.parseColor(discount.getBackgroundColor()));
} else {
viewHolder.mainLayout.setBackgroundColor(Color.parseColor(prev_discount.getBackgroundColor()));
setRoundedBackground(viewHolder.secondLayaout, Color.parseColor(discount.getBackgroundColor()));
}
return view;
}
private void setRoundedBackground(View view,int color){
final GradientDrawable gradientDrawable = (GradientDrawable) view.getBackground().mutate();
gradientDrawable.setColor(color);
gradientDrawable.invalidateSelf();
}
Here is the result
You should override getView method.
Sample code:
View getView(int position, View convertView, ViewGroup parent){
Object data = getItem(positon);
//usually data object should have type property
if(data.type == TYPE1){
return getLayoutInflater().inflate(R.layout.custom_xml1, null);
}else (data.type == TYPE2){
return getLayoutInflater().inflate(R.layout.custom_xml2, null);
}else{
return getLayoutInflater().inflate(R.layout.custom_xml, null);
}
};
Note:You should reuse convertView object for performance.
Ok, As I have sort of time I manage to write few steps to achieve your task.
1. Make Custom drawable using xml in drawable folder with top corners have radius..
2. Now in your Listview attributes just define negative divider height
Like, android:dividerHeight="-20dp"
3. Set the Custom Drawable as a background of List row in getView().
Also its nice if you able to set color to drawable at dynamically for list row. (In getView() of Custom Adapter).
This what I have achieved from above steps:

Can't change Image source in my listview

I'm working on an e-commerce application, i need to display a list of products -a product = one ImageView and some textViews- from the database, but when i extract the data from the database, everting works fine except the imageView, it shows the same image that is in the source Layout.
this is the getView() Method in my adapter.
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView==null)
{
holder=new ViewHolder();
convertView = inflater.inflate(R.layout.lesproduits, null);
holder.nomduProduit = (TextView)convertView.findViewById(R.id.nomProduit);
holder.prixDuProduit = (TextView)convertView.findViewById(R.id.prixProduit);
holder.imageDuProduit = (ImageView)convertView.findViewById(R.id.imageProduit);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
Bitmap bitmapImage = BitmapFactory.decodeFile(path+File.separator+lesProduits.get(position).getImage());
Drawable drawableImage = new BitmapDrawable(bitmapImage);
System.out.println(path+File.separator+lesProduits.get(position).getImage());
holder.imageDuProduit.setBackgroundDrawable(drawableImage);
holder.nomduProduit.setText(lesProduits.get(position).getNomDuProduit());
holder.prixDuProduit.setText(lesProduits.get(position).getPrixDuProduit());
return convertView;
}
and below is the source Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageProduit"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="30dp"
android:layout_marginTop="5dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/nomProduit"
android:layout_marginTop="5dp"
android:layout_width="170dp"
android:layout_height="30dp"
android:layout_toRightOf="#+id/imageProduit"
android:text="Smart phone"
android:textSize="25sp" />
<TextView
android:id="#+id/prixProduit"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/nomProduit"
android:layout_below="#+id/nomProduit"
android:layout_marginTop="5dp"
android:text="Large Text"
android:textSize="15sp" />
</RelativeLayout>
You are changing the background, not the foreground.
ImageView has both foregrond and background images.
instead of this
holder.imageDuProduit.setBackgroundDrawable(drawableImage);
use this
holder.imageDuProduit.setImageDrawable(drawableImage);

Android's RelativeLayout seems broken

I'm working on a layout where I use a ListView with RelativeLayout line items. The lineitems themselves are not displaying correctly.
The issue is that the txtVideoDuration TextView is drawn at the top of the line item instead of the bottom. Because of this the txtVideoTitle gets a height of 0. As you can see in the XML the txtVideoDuration is supposed to be clamped to the bottom of the ListView.
My goal is to have the layout resemble the tutorial that google gave me. Example: http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html
I'm using Android 2.0.1. I've even plugged in the example layout with out modification into the ListView and the same behavior happens.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/imgVideoThumbnail"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:minHeight="64dip"
android:layout_marginRight="6dip"
android:src="#drawable/icon" />
<TextView
android:id="#+id/txtVideoDuration"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="#+id/imgVideoThumbnail"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="0:00:00" />
<TextView
android:id="#+id/txtVideoTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imgVideoThumbnail"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/txtVideoDuration"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="[Title]"
android:textColor="#FFFFFF" />
</RelativeLayout>
This simple case works. This is the root XML layout for the activity. The buggy code at the top is the line items in the list view. It seems that the ListView itself is breaking it.
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#+id/listVideoCatalog"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id="#+id/txtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Hello World" />
</RelativeLayout>
</merge>
This is the getView Code that inflates the line item into the ListView.
static class ViewHolder
{
TextView txtTitle;
ImageView imgThumbnail;
TextView txtDuration;
Uri videoLocation;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if(convertView == null)
{
LayoutInflater li = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.listitem_videolineitem, null);
holder = new ViewHolder();
holder.txtDuration = (TextView) convertView.findViewById(R.id.txtVideoDuration);
holder.txtTitle = (TextView) convertView.findViewById(R.id.txtVideoTitle);
holder.imgThumbnail = (ImageView) convertView.findViewById(R.id.imgVideoThumbnail);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
VideoFile video = this.videos.get(position);
holder.txtDuration.setText(millisToTimestamp(video.videoDuration));
holder.txtTitle.setText(video.videoTitle);
// Some debugger visual code.
holder.txtDuration.setBackgroundColor(Color.GREEN);
holder.txtTitle.setBackgroundColor(Color.CYAN);
return convertView;
}
This was answered in the comment of the accepted answer. Just to make it clear, this is the answer:
Change
li.inflate(R.layout.listitem_videolineitem, null);
to
li.inflate(R.layout.listitem_videolineitem, parent, false);
How are you inflating your row views that are "buggy"? Can you provide a code snippet?
Also, android:orientation="vertical" is not valid for RelativeLayout.

Categories

Resources