How To 4 Icons In Right Side Of Each Row In List View
Solution 1:
Define and use a xml layout file for your list item row. The row will contain 4 ImageViews on the right side along with any other Views. And use this as the layout for each row. And based on the position in your CustomAdapter
class you can get references to each of your rows.
Now, inflate this xml layout for list item row in getView()
of CustomAdapter.
Solution 2:
you have to create custm view for your list viewor you can simply create a xml file for that and later in Adapter class inflate it.
like here i have create a xml file with two TextViews.
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.two_text, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView
.findViewById(R.id.TextView01);
holder.text2 = (TextView) convertView
.findViewById(R.id.TextView02);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text1.setText(CountriesList.abbreviations[position]);
holder.text2.setText(CountriesList.countries[position]);
return convertView;
}
Solution 3:
To save time doing it programmatically, you can do as follow:
- Create list_view_item xml file (represent each view item). To do flexible alignment, you should use
RelativeLayout
. - Inflate the above xml layout in your array adapter
(1) Create list_view_item.xml
for item layout:
The key work is set the first item to parent view's right:
android:layout_alignParentRight="true"
Then the following items are aligned by previous item:
android:layout_alignParentLeft="@+id/id_of_prev_item"
(EDITED for 3 images:)
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><ImageViewandroid:id="@+id/img1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true" /><ImageViewandroid:id="@+id/img2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="@+id/img1" /><ImageViewandroid:id="@+id/img3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="@+id/img2" /><TextViewandroid:id="@+id/description"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_alignParentLeft="@+id/img3"android:fadingEdge="vertical" /></RelativeLayout>
(2) Inflate item layout in CustomImageListAapter
:
Suggestion: extend your CustomImageListAapter
class from ArrayAdapter<T>
to more specific use of data item and make your code more comprehensive.
publicclassCustomImageListAapter extend ArrayAdapter<YourDataItem>
{
@Overridepublic View getView(int position, View convertView, ViewGroup parent)
{
intitem_view_id= R.layout.list_view_item;
LinearLayoutholderView=newLinearLayout(getContext());
StringinflaterName= Context.LAYOUT_INFLATER_SERVICE;
LayoutInflaterinflater= (LayoutInflater) getContext().getSystemService(inflaterName );
inflater.inflate(item_view_id, holderView, true);
//YourDataItem: is your class represent each row on your databaseYourDataItemitem= getItem(position);
//TODO: do your stuff of works with your view item and data herereturn holderView;
}
}
Post a Comment for "How To 4 Icons In Right Side Of Each Row In List View"