Grid Items are changing when scrolling - android

Hi I am working with custom GridView.
The GridView placed in the following xml/layout file.
<?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" >
<View
android:id="#+id/music_home_ad_view"
android:layout_width="match_parent"
android:layout_height="50dp" />
<ScrollView
android:id="#+id/music_home_root_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ScrollView>
<FrameLayout
android:id="#+id/music_home_promo_frame"
android:layout_width="match_parent"
android:layout_height="#dimen/music_home_promo_height"
android:layout_marginTop="20dp" >
<android.support.v4.view.ViewPager
android:id="#+id/music_home_promo_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.raaga.home.CirclePageIndicator
android:id="#+id/music_home_page_indicator"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_gravity="bottom"
android:padding="10dp" />
</FrameLayout>
<GridView
android:id="#+id/music_home_grid_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/music_home_promo_frame"
android:numColumns="3" >
</GridView>
</RelativeLayout>
The GridView contains the following views
music_grid_item.xml
<?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"
android:background="#android:color/transparent"
>
<ImageView
android:id="#+id/music_grid_image"
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:src="#drawable/new_releases"
/>
<TextView
android:id="#+id/music_grid_category_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/music_grid_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="New Releases"
android:textColor="#color/text_white"
/>
</RelativeLayout>
I have used the custom adapter class and followed this link
MusicCategoryAdapter.java
public class MusicCategoryAdapter extends BaseAdapter{
ArrayList<Integer> categoryImageList;
ArrayList<String> categoryNameList;
Context mContext;
public MusicCategoryAdapter(Context mContext, ArrayList<Integer> categoryImageList, ArrayList<String> categoryNameList) {
this.mContext= mContext;
this.categoryImageList = categoryImageList;
this.categoryNameList = categoryNameList;
}
#Override
public int getCount() {
//send the list length
return categoryImageList.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
GridHolder holder;
View grid = convertView;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
convertView = inflater.inflate(R.layout.music_grid_item, null);
holder = new GridHolder();
holder.categoryTitle = (TextView) convertView.findViewById(R.id.music_grid_category_name);
holder.categoryImage = (ImageView)convertView.findViewById(R.id.music_grid_image);
holder.categoryTitle.setText(categoryNameList.get(position));
holder.categoryImage.setImageResource(categoryImageList.get(position));
convertView.setTag(holder);
} else {
holder = (GridHolder) convertView.getTag();
}
return convertView;
}
public class GridHolder{
ImageView categoryImage;
TextView categoryTitle;
}
}
I am facing the problem that the items are repeating by changing the position when scrolling.
Could anyone help on this problem? What mistake I did in this?

Put the scrollview at the starting of relative layout and end the tag in the end of the relative layout.
This would make your entire layout scrollable and you will overcome the problem.

Related

Horizontal GridView with customAdaptor not displaying properly

I want to display a single row of 5 images which then I can click on, this is what I hope to get:
[1][2][3][4][5]
This is what I actually get:"____" is a large, long blank area
[1]________________________
[2]________________________
[3]________________________
[4]________________________
[5]________________________
At first I thought there was something up with the orientation so I tried both "horizontal" and "vertical" but nothing worked.
Here is the adaptor code:
public class CustomTopGridMenuAdaptor extends BaseAdapter {
private Context mContext;
private final int[] gridViewImageId;
private ImageView imageViewAndroid;
public CustomTopGridMenuAdaptor(Context context, int[] gridViewImageId) {
mContext = context;
this.gridViewImageId = gridViewImageId;}
#Override
public int getCount() {
return gridViewImageId.length;
}
#Override
public Object getItem(int i) {
return null;
}
public void setImageSource (int i,ImageView v){
imageViewAndroid.setImageResource(gridViewImageId[i]);
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View convertView, ViewGroup parent) {
View gridViewAndroid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
gridViewAndroid = new View(mContext);
gridViewAndroid = inflater.inflate(R.layout.android_custom_gridview_layout_top, null);
imageViewAndroid = (ImageView)
gridViewAndroid.findViewById(R.id.android_gridview_image_top);
setImageSource(i,imageViewAndroid);
} else {
gridViewAndroid = (View) convertView;
}
return gridViewAndroid;
}
}
As far as it goes the adaptor is working just fine.
This is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/android_custom_gridview_layout_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="#+id/android_gridview_image_top"
android:layout_width="50dp"
android:layout_height="50dp"/>
</LinearLayout>
This is the xml segment in the activity layout, where the menu will be displayed:
<GridView
android:id="#+id/android_gridview_menu_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="196dp">
Can you tell me why it's not working?
Use the android:numColumns="2" in your GridView if you want 5 then change the android:numColumns="5"
<GridView
android:id="#+id/android_gridview_menu_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:numColumns="2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="196dp">
I don't think that gridviews can be made horizontally scrollable. Android has provided HorizontalScrollView it will scroll your view horizontaly. try this.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</GridView>
</LinearLayout>
</HorizontalScrollView>
Happy coding!!

How to add a white line below every ListView Item in xml?

My Problem is --> I put a white line as a view in the Fragment item xml but it doesn't appear when i debug it. How can i get the changes i make in the fragment item xml file. Because i tried some little changes like alpha property change but it didnt change is it because of this is a listview and has itself design? Please help me about that problem.
The xml code and adapter code are below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="5dp"
>
<ImageView
android:id="#+id/menulogo"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/infoicon"
android:layout_gravity="center"
android:paddingTop="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/txtMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Company Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1" />
</LinearLayout>
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="#+id/txtMenu"
android:background="#FFFFFF"
/>
</LinearLayout>
My listview adapter codes right down below.
public class MenuListAdapter extends ArrayAdapter<Menu_Item> {
private final ArrayList<Menu_Item> list;
private final Activity context;
private int[] colors = new int[]{0x34a4a4a4, 0x34fafafa};
public MenuListAdapter(Activity context, ArrayList<Menu_Item> list) {
super(context, R.layout.menu_item, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
public ImageView menulogo;
public TextView txtMenu;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.menu_item, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.menulogo = (ImageView) view.findViewById(R.id.menulogo);
viewHolder.txtMenu = (TextView) view.findViewById(R.id.txtMenu);
view.setTag(viewHolder);
int colorPos = position % colors.length;
view.setBackgroundColor(colors[colorPos]);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.txtMenu.setText(list.get(position).getMenuName());
//holder.menulogo.setImageBitmap(list.get(position).getMenuImage());
String menuName=list.get(position).getMenuName();
if (menuName.equals("Info")){
holder.menulogo.setImageResource(R.drawable.infoicon);
}
if (menuName.equals("Odalar")){
holder.menulogo.setImageResource(R.drawable.accomodation);
}
if (menuName.equals("Galeri")){
holder.menulogo.setImageResource(R.drawable.galeryicon);
}
if (menuName.equals("Aktiviteler")){
holder.menulogo.setImageResource(R.drawable.activitiesicon);
}
if (menuName.equals("Robin's Kids Club")){
holder.menulogo.setImageResource(R.drawable.kidsclub);
}
if (menuName.equals("Restaurants")){
holder.menulogo.setImageResource(R.drawable.restaurantsicon);
}
view.setId(list.get(position).getMenu_id());
return view;
}
#Override
public int getViewTypeCount() {
if (getCount() != 0)
return getCount();
return 1;
}
}
I found an answer to my question and wanted to share it with you.
I only used these 2 properties below of ListView
android:divider="#FFFFFF"
android:dividerHeight="1dip"
Like this...
<ListView
android:id="#+id/menuList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:divider="#FFFFFF"
android:dividerHeight="1dip"
/>
In ListView XML add these two lines
<ListView
android:divider="#android:color/white"
android:dividerHeight="5dip"
.
.
</ListView>
Try to change the View with id line for a Space component. It is an extension of View, and works better for what you want.
Here is a description of the widget:
https://developer.android.com/reference/android/widget/Space.html

Two views with different heights in a viewflipper on a gridview tile

I have a GridView which has a ViewFlipper in each tile. Each view in the ViewFlipper has a different size, but when the tile is flipped, both views are forced to the same size as the GridView column. What i've tried:
Googled
Set android:measureAllChildren to false on ViewFlipper(only works with ListView)
Left android:columnWidth unspecified
Made ViewFlipper root tag in grid tile layout file
grid_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="180dp" android:layout_height="150dp">
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:measureAllChildren="false"
android:id="#+id/view_flipper_3"
>
<RelativeLayout
android:layout_width="180dp"
android:layout_height="150dp"
android:id="#+id/front2"
android:background="#088980"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/commitmentNumber"
android:textSize="25dp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="220dp"
android:layout_height="190dp"
android:background="#000000"
android:id="#+id/back_2"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/commitmentPartOne"
android:paddingBottom="5dp"
android:textSize="25sp"
android:text="Part One"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/commitmentPartTwo"
android:textSize="25sp"
android:text="Part Two"
android:paddingBottom="5dp"
android:layout_below="#+id/commitmentPartOne"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/commitmentPartThree"
android:textSize="25sp"
android:text="Part Three"
android:layout_below="#+id/commitmentPartTwo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
</ViewFlipper>
</RelativeLayout>
fragment_with_gridview.xml:
<?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">
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/sixCommitmentsGridView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:numColumns="2"
android:gravity="center"
android:columnWidth="179dp"
android:stretchMode="columnWidth"
/>
</RelativeLayout>
GridViewAdapter.java:
public class SixCommitmentsGridAdapter extends BaseAdapter {
Context context;
String[] numbers;
public SixCommitmentsGridAdapter(Context context, String[] numbers) {
this.context = context;
this.numbers = numbers;
}
#Override
public int getCount() {
return numbers.length;
}
#Override
public Object getItem(int position) {
return numbers[position];
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
final ViewFlipper flipper;
TextView commitmentNumber;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.six_commitments_grid_item, parent, false);
}else{
view = convertView;
}
flipper = (ViewFlipper) view.findViewById(R.id.view_flipper_3);
commitmentNumber = (TextView) view.findViewById(R.id.commitmentNumber);
commitmentNumber.setText(numbers[position]);
flipper.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(position % 2 == 0 || position == 0){
AnimationFactory.flipTransition(flipper, AnimationFactory.FlipDirection.RIGHT_LEFT, 200);
}else {
AnimationFactory.flipTransition(flipper, AnimationFactory.FlipDirection.LEFT_RIGHT, 200);
}
}
});
return view;
}
}
Managed to achieve the same grid-style layout with my intented ViewFlipper effect using a StaggeredGridLayoutManager and a RecyclerView.
In Main RelativeLayout contain ViewFlipper, you set height and width!
set them "wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
maybe worked.
good luck.
Update
Use this library:
https://github.com/etsy/AndroidStaggeredGrid

ListView show only the first item in the list

I search a lot for an answer and didn't find one that suit me.
I found out that when I set my layout_heigh to 500dp -> all the item shown, but when it has normal size (layout_heigh=wrap_content) then only the first item is shown.
this is my code:
activity_main.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">
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Add Task"
android:onClick="addTask" />
<ListView android:id="#+id/myListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"/>
</LinearLayout>
xml_item.xml: this is for one item to duplicate in the listView
<?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"
android:descendantFocusability="blocksDescendants">
<TextView
android:layout_width="100dp"
android:layout_height="50dp"
android:id="#+id/itemText"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="15dp"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/doneBtn"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text="Done" />
</RelativeLayout>
MyListAdapter: a class in the main_activity that extends the ArrayAdapter class so I can put in one row both TextView and a button.
private class MyListAdapter extends ArrayAdapter<String> {
private int layout;
public MyListAdapter(Context context, int resource, List<String> objects) {
super(context, resource, objects);
layout= resource;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder mainHolder= null;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView= inflater.inflate(layout, parent, false);
ViewHolder viewHolder= new ViewHolder();
viewHolder.item= (TextView) convertView.findViewById(R.id.itemText);
viewHolder.btn= (Button) convertView.findViewById(R.id.doneBtn);
viewHolder.btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), itemArray.get(position), Toast.LENGTH_SHORT).show();
}
});
convertView.setTag(viewHolder);
}
else {
mainHolder= (ViewHolder) convertView.getTag();
mainHolder.item.setText(getItem(position));
}
return convertView;
}
public class ViewHolder {
TextView item;
Button btn;
}
}
Thanks for all! :)
but when it has normal size (layout_heigh=wrap_content)
It is a very bad idea using a ListView by giving it a height=wrap_content.
This forces ListView to measure a few children out of the adapter at layout time, to know how big it should be.
You can check it your self debugging the getView() method inside the adapter.
In your case, using a LinearLayout just add a top margin (50dp as the Button) to your listView and use layout_heigh=match_parent.
Otherwise use a RelativeLayout.
Change your listview to take up as much room as is can considering the height of any sibling views (in this case your button). Here's how to do that with the android:layout_weight attribute
<?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">
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Add Task"
android:onClick="addTask" />
<ListView android:id="#+id/myListView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
</LinearLayout>

Set different icons for each row

Above is the main screen of my app with a custom adapter for listview. How do I put a different icon for each row in the listview? I tried putting an ImageView in the xml but it overwrites my whole screen only showing an icon.
MainAcitivty xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/hp_color"
tools:context=".MainActivity" >
<TextView
android:id="#+id/cityText"
style="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textSize="28sp" />
<ImageView
android:id="#+id/condIcon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_below="#id/cityText"
android:contentDescription="weather icon" />
<TextView
android:id="#+id/condDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/condIcon"
android:textSize="20sp" />
<ListView
android:id="#+id/mainListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<ImageButton
android:id="#+id/btnPicturePage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="picturePage"
android:src="#drawable/photo" />
Custom adapter:
public class WeatherAdapter extends ArrayAdapter<String> {
private final Activity context;
private ArrayList<String> weatherData;
static class ViewHolder {
public TextView text;
public ImageView image;
}
public WeatherAdapter(Activity context, ArrayList<String> weatherData) {
super(context, R.layout.list, weatherData);
this.context = context;
this.weatherData = weatherData;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
// reuse views
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.list, null);
// configure view holder
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.rowTextView);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
ArrayList<String> s = new ArrayList<String>(weatherData);
String []sa = new String [s.size()];
sa = s.toArray(sa);
holder.text.setText(sa[position]);
if (sa[position].startsWith("Air pressure")) {
rowView.setBackgroundResource(R.color.skyblue) ;
}
return rowView;
}
List xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rowTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#color/white" >
</TextView>
Your list.xml should be something similar to this (taken from one my files)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="center_vertical" android:orientation="horizontal"
android:background="#drawable/xml_pressed_bg" android:clickable="true" android:layout_width="fill_parent"
android:layout_height="54dip"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ttshow="http://schemas.android.com/apk/res-auto">
<ImageView android:id="#+id/imgThumb" android:layout_width="42.0dip" android:layout_height="42.0dip" android:scaleType="fitXY"
android:src="#drawable/sample_dj" />
<TextView android:textSize="14.0sp" android:textColor="#ff666666" android:id="#+id/txtName"
android:layout_width="180dip" android:layout_height="wrap_content"
android:singleLine="true" android:shadowColor="#99ffffff" style="#style/TextShadowLight"
android:text="Hello" android:paddingLeft="10dip"/>
</LinearLayout>
Every row item has an image (imgThumb). This needs to be changed or set to a static image, depending on your needs. This is done in the adapters' getView() method.
imgThumb.setImageResource(R.drawable.my_image);
Private TypedArray img;
img=getResource.obtainTypedArray(R.array.imgIcon)
if (sa[position].startsWith("Air pressure")) {
rowView.setBackgroundResource(R.color.skyblue) ;
holder.image.setImageResource(img.gerResourceId[0]);
}else if (sa[position].startsWith("Air Condition")) {
holder.image.setImageResource(img.gerResourceId[1]);
}

Categories

Resources