Indenting ListView items Android - android

I am trying to indent listView row by certain factor. For this, I used view.layout() and view.setX() method but they don't work or result in forceclose. Is there a way to achieve this result. Here is my code:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View newRowView = convertView;
ViewHolder viewHolder;
if(newRowView == null)
{
LayoutInflater inflator = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
newRowView = inflator.inflate(R.layout.list_view_images, parent,false);
//newRowView.layout(100*(position/list.size()), 0, 0, 0); // not working
newRowView.setX(100*(position/list.size())); // causing force close
viewHolder = new ViewHolder();
viewHolder.appIcon = (ImageView) newRowView.findViewById(R.id.imageView1);
viewHolder.appName = (TextView) newRowView.findViewById(R.id.textView1);
viewHolder.appName.setText(names.get(position));
newRowView.setTag(viewHolder);
}
list_view_images.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
I am trying to indent the list in semi circular fashion.
What can I do achieve required results?
Regards

Update your getView() method as follows:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View newRowView = convertView;
ViewHolder viewHolder;
if (newRowView == null) {
LayoutInflater inflator = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
newRowView = inflator.inflate(R.layout.list_view_images, parent, false);
viewHolder = new ViewHolder();
viewHolder.innerContainer = (LinearLayout) newRowView.findViewById(R.id.innerContainer);
viewHolder.appIcon = (ImageView) newRowView.findViewById(R.id.imageView1);
viewHolder.appName = (TextView) newRowView.findViewById(R.id.textView1);
viewHolder.appName.setText(list.get(position));
newRowView.setTag(viewHolder);
}
else {
viewHolder = (ViewHolder) newRowView.getTag();
}
float shiftRight = 100 * ((position * 1.0f) / list.size());
viewHolder.innerContainer.setPadding((int) shiftRight, 0, 0, 0);
//...
//...
return newRowView;
}
Update your XML layout as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/innerContainer"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
Update your ViewHolder to contain another field as following:
public LinearLayout innerContainer;
Explanation: Basically, we put your original XML layout inside a LinearLayout that acts as an outer container. The we assign padding to the innerContainer (original layout) with respect to the outer layout

Related

Making ExpandableListView respect item margins and padding

I have an ExpandableListView that I'm populating with items. I'd like to have the header (here, "meat") be wider than the list items.
However, ExpandableListView doesn't seem to respect margins/padding defined in XML, and also fails to respect programatically-set padding for the items. It does modify the parent ("meat") but the same code doesn't work for the items.
How can I do this?
Here's the relevant part of my custom adapter:
#Override
public View getGroupView(int position, boolean isExpanded, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_category, null);
}
view.setPadding(10, 0, 10, 0); //RESPECTED
initializeGroupComponents(view, getGroup(position));
return view;
}
#Override
public View getChildView(int position, int expandedPosition, boolean isLastChild, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_ingredient, parent, false);
}
view.setPadding(10, 2, 10, 2); //DOES NOT WORK
initializeChildComponents(view, getChild(position, expandedPosition));
return view;
}
The relevant portions of my XML:
The group:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_categoryContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="vertical">
The item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/row"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginBottom="1dp"
android:layout_marginEnd="6dp"
android:layout_marginStart="6dp"
android:background="#android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
Take one extra layout for header and add margin
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_categoryContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp">
//other content
</LinearLayout>
</LinearLayout>

I cannot load listview on my Android phone

I cannot load listview on my phone. It displays the error in the logcat:
03-24 05:27:14.537: D/AbsListView(22125): unregisterIRListener() is called
My code is as follow
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
setHasOptionsMenu(true);
rootView = inflater.inflate(R.layout.fragment_event, container, false);
listView = (ListView) rootView.findViewById(R.id.eventListView);
listView.setVisibility(View.VISIBLE);
listView.setClickable(true);
EventArrayAdapter eArrayAdapter = new EventArrayAdapter(getActivity(), R.layout.rowlayout, events);
listView.setAdapter(eArrayAdapter);
eArrayAdapter.notifyDataSetChanged();
return rootView;
}
rowlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/eventDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#1d766f"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/eventMonth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e2fffd"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#0083af" />
<TextView
android:id="#+id/eventTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e2fffd"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#1d766f" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/eventName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#0083af"/>
<TextView
android:id="#+id/eventLocation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
mainlayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/btnAllEvent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All Events"
/>
<ListView
android:id="#+id/eventListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"/>
</LinearLayout>
Unfortunately, it doesnot show anything, even the listview itself. Please help me. Thank you
Update: I use the view Holder pattern
You have to return the view simply.
Also For a better scrolling you need to implement and understand the ViewHolder pattern.
Reason why you should use it is because:
layout inflations are expensive operations.
If you do something like this:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = mContext.getLayoutInflater();
View item = mInflater.inflate(R.layout.list_item, null);
MyObj data = getItem(position);
((TextView) item.findViewById(R.id.text1)).setText(data.text1);
((TextView) item.findViewById(R.id.text2)).setText(data.text2);
((TextView) item.findViewById(R.id.longtext)).setText(data.longText);
return item;
}
Please don't do it, because the adapter will create a new view for every position and if you have a very long list it will cause lag scroll. Imagine you have 500 item in the list, the adapter have to create 500 views!!!
So the ViewHolder pattern fix this problem by changing that code from above like this:
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(TAG, "position=" + position);
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, parent, false);
holder = new ViewHolder();
holder.text1 = (TextView) convertView.findViewById(R.id.text1);
holder.text2 = (TextView) convertView.findViewById(R.id.text2);
holder.longtext = (TextView) convertView.findViewById(R.id.longtext);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
MyObj data = getItem(position);
holder.text1.setText(data.text1);
holder.text2.setText(data.text2);
holder.longtext.setText(data.longText);
return convertView;
}
The convertView from the getView method will have a non-null value when ListView is asking you recycle the row layout. So, when convertView is not null, you should simply update its contents instead of inflating a new row layout.
What this snippet does goes like this:
If the ConvertView is null it will inflate the layout and save each view under the ViewHolder class, what ViewHolder does is to save the views, then you save the ViewHolder in the ConverView with setTag(Object object), If convertView isn't Null then it get the ViewHolder object like this: holder = (ViewHolder) convertView.getTag();
And then it get the current object from the list with the position variable from the getView method and reference everyView through the ViewHolder instance.
Also don't use android:layout_height="wrap_content" because the listView has to call getView() lot of time to know how big it should be, so use android:layout_height="fill_parent" instead.

Gridview row height mess up when scrolling

I'm using a gridview to present various article items consisting of two textfield. Because of different amount of text the height of each item is different and a row should be sized with the height of the biggest item of a row. The gridview uses colnum = autofit.
As the following screenshot before and after scrolling show, the behaviour is as expected since i scroll down and up again: Rows mess up and cut content of big items.
What am I missing?
Gridview before scrolling:
GridView after scrolling down and up:
Further code:
item xml code
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="14dp"
android:textColor="#040404"
android:textSize="20sp"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="#343434"
android:textSize="14sp"
android:typeface="serif" />
</LinearLayout>
My ListAdapter (recycles views if possible):
public class SearchResultListViewAdapter extends ArrayAdapter
{
Context context;
Newspaper newspaper;
List<SearchResultListItem> searchResults;
int viewStyle;
public SearchResultListViewAdapter(Context context, int resourceId, List<SearchResultListItem> searchResults, int viewStyle) {
super(context, resourceId, searchResults);
this.context = context;
this.searchResults = searchResults;
this.viewStyle = viewStyle;
}
/* private view holder class */
private class ViewHolder
{
TextView txtTitle;
TextView txtText;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View gridItem;
ViewHolder holder = null;
if (convertView == null)
{
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (this.viewStyle == 0)
{
gridItem = mInflater.inflate(R.layout.searchresult_list_item, null);
} else
{
gridItem = mInflater.inflate(R.layout.searchresult_grid_item, null);
}
holder = new ViewHolder();
} else {
gridItem = convertView;
holder = (ViewHolder) gridItem.getTag();
}
holder.txtText = (TextView) gridItem.findViewById(R.id.text);
holder.txtTitle = (TextView) gridItem.findViewById(R.id.title);
gridItem.setTag(holder);
SearchResultListItem rowItem = getItem(position);
holder.txtText.setText(Html.fromHtml(rowItem.getText()), TextView.BufferType.SPANNABLE);
holder.txtTitle.setText(Html.fromHtml(rowItem.getTitle()), TextView.BufferType.SPANNABLE);
return gridItem;
}
}
And finally my activity layout containing the gridview:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<EditText
android:id="#+id/searchPatternInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/loadSearchResults"
android:imeOptions="actionSearch"
android:inputType="text" />
<ImageButton
android:id="#+id/showExtendedSearch"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_action_filter" />
<ImageButton
android:id="#+id/loadSearchResults"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/showExtendedSearch"
android:src="#drawable/ic_action_search" />
</RelativeLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff" >
<ImageSwitcher
android:id="#+id/nothingLoaded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/ic_nothing_loaded" >
</ImageSwitcher>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" >
<GridView
android:id="#+id/searchResultThumbnailsGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="160dp"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:gravity="center"
android:horizontalSpacing="4dp"
android:listSelector="#drawable/list_selector"
android:numColumns="auto_fit"
android:padding="10dp"
android:layout_weight="1"
android:stretchMode="columnWidth"
android:verticalSpacing="4dp" />
</LinearLayout>
</RelativeLayout>
</TableRow>
</TableLayout>
You seem to have confusion using View.setTag() and View.getTag() methods. Try this:
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder = null;
if (convertView == null)
{
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (this.viewStyle == 0)
{
convertView = mInflater.inflate(R.layout.searchresult_list_item, null);
} else
{
convertView = mInflater.inflate(R.layout.searchresult_grid_item, null);
}
holder = new ViewHolder();
//Always use View.findViewById() and View.setTag() here
holder.txtText = (TextView) convertView.findViewById(R.id.text);
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(holder);
} else {
//Always use View.getTag() here
holder = (ViewHolder) convertView.getTag();
}
//Always set your data here
SearchResultListItem rowItem = getItem(position);
holder.txtText.setText(Html.fromHtml(rowItem.getText()), TextView.BufferType.SPANNABLE);
holder.txtTitle.setText(Html.fromHtml(rowItem.getTitle()), TextView.BufferType.SPANNABLE);
return convertView;
}
I moved on to use a third party component. The StaggeredGridView workes fine for me, more information can be found here.

Filling ListView out

I'm working on project and main layout contains ListView. I want to dynamically add subItems to ListViewItem View. My main layout is as follows :
main_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView"/>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
</ListView>
</RelativeLayout>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#android:color/transparent" >
</LinearLayout>
And I want to add TextView to returned view in getView with following properties :
Height : fill_parent
Width : wrap_content
Text : Text View Item
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) this.M_context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, parent, false);
return convertView;
}
Please note that, I want to dynamically add subItems to ListViewItem. You can suppose that, I have array of TextView and want to fill my listView using this Items. How can I do this scenario ? I can not find any result with searching on other threads and aslo Google. So, Could any one please help me to solve my problem ?
Thanks in Advance :)
This was my getView() method.
main.xml
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/button1"
android:cacheColorHint="#android:color/transparent"
android:divider="#00ff00"
android:fastScrollEnabled="true"
android:focusable="false"
android:listSelector="#000000"
android:paddingTop="5dp"
android:saveEnabled="true" >
</ListView>
item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Adapter
class CustomAdapter extends ArrayAdapter<String> {
public CustomAdapter(Context context, int resource, List<String> objects) {
super(context, resource, objects);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
/*convertView = mInflater.inflate(R.layout.item, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
holder = (ViewHolder) convertView.getTag();
holder.getAppName().setText(str.get(position));*/
if(position==0)
{
ImageView iv = new ImageView(getApplicationContext());
iv.setBackgroundResource(R.drawable.ic_launcher);
convertView = iv;
}
else if(position==1)
{
TextView tv = new TextView(getApplicationContext());
tv.setText("text view");
convertView = tv;
}
else
{
EditText et = new EditText(getApplicationContext());
et.setText("ET go home");
convertView = et;
}
return convertView;
}
private class ViewHolder {
private View pathRow;
private TextView appNameView = null;
public ViewHolder(View row) {
pathRow = row;
}
public TextView getAppName() {
if (null == appNameView) {
appNameView = (TextView) pathRow.findViewById(R.id.tv);
}
return appNameView;
}
}
}
The commented out portion is the one used to be. The code below it is the one which I used to dynamically generate the view and return them. my listitem.xml still has a textView in it. But the adapter sets the view which we are returning from getView(). This works for me.
I really don;t see the point of the LinearLayout in your item.xml. You can do that in your own code.

Android, changing background of list in array adapter?

In my application i have list which i inflate it with array adapter. every thing is OK and i have my result in the list.
I like to change background color of list (even rows red for example and odd rows green).
This is xml of my rows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="#+id/rllist"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:layout_marginBottom="15dip"
>
<TextView
android:id="#+id/outstanding_contractdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="15sp" />
<TextView
android:id="#+id/outstanding_contractno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/outstanding_contractdate"
android:paddingLeft="20dip"
android:textColor="#ffffff"
android:textSize="15sp" />
<TextView
android:id="#+id/outstanding_contractamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="15sp" />
</RelativeLayout>
</LinearLayout>
I have written following codes:
static class ViewHolder {
RelativeLayout rlList;
TextView tvContDate;
TextView tvContNo;
TextView tvContAmount;
}
and in Array Adapter I have this one:
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
View row = convertView;
if(row == null){
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.list_outstanding, parent, false);
//convertView = mInflater.inflate(R.layout.list_outstanding, parent, false);
holder = new ViewHolder();
holder.rlList = (RelativeLayout) convertView.findViewById(R.id.rllist);
holder.tvContDate = (TextView) row.findViewById(R.id.outstanding_contractdate);
holder.tvContNo = (TextView) row.findViewById(R.id.outstanding_contractno);
holder.tvContAmount = (TextView) row.findViewById(R.id.outstanding_contractamount);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
holder.tvContDate.setText(llData.get(position).split(",")[0].trim());
holder.tvContNo.setText(llData.get(position).split(",")[1].trim());
holder.tvContAmount.setText(llData.get(position).split(",")[2].trim());
if(position%2 != 0)
holder.rlList.setBackgroundColor(0x00FF00);
else
holder.rlList.setBackgroundColor(0XFF0000);
return(row);
}
after running application when i reach to this code, an error occurs. according to LogCat it is "Null Pointer Exception" and points to this line in getView():
holder.rlList = (RelativeLayout) convertView.findViewById(R.id.rllist);
it seems everything is OK, but I don't know where my problem is?!!!
===========
Update
I have changed above line to:
holder.rlList = (RelativeLayout) row.findViewById(R.id.rllist);
and now i have my result but background did not applied?!!!
Try using
if(position%2 != 0)
holder.rlList.setBackgroundColor(Color.parseColor("#00ff00"));
else
holder.rlList.setBackgroundColor(Color.parseColor("#ff0000"));

Categories

Resources