How to change the Android gallery selected item color? -


i trying write code display android gallery view infinite list. able display gallery in screen want change color of selected item in gallery.

mycode:

mainactivity.java

package com.example.mycircularlistview;  import android.app.activity; import android.os.bundle; import android.widget.gallery;  public class mainactivity extends activity {  string[] txtdata;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     gallery gallery = (gallery) findviewbyid(r.id.mygallery);           txtdata = new string[12];          for(int i=0;i<txtdata.length;i++){              txtdata[i] = ""+i;         }          gallery.setadapter(new galleryadapter(this,txtdata));          gallery.setspacing(18);   }   } 

galleryadapter.java

package com.example.mycircularlistview;  import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.textview;  public class galleryadapter extends baseadapter {      private layoutinflater inflater = null;      string[] txtdata;      public galleryadapter(context c, string[] txtdata) {          inflater = (layoutinflater) c.getsystemservice(context.layout_inflater_service);         this.txtdata = txtdata;     }      public int getcount() {          if (txtdata != null) {              return integer.max_value;          } else {              return 0;          }      }      public object getitem(int position) {          if(position >= txtdata.length) {              position = position % txtdata.length;          }          return position;     }      public long getitemid(int position) {          if(position >= txtdata.length) {              position = position % txtdata.length;          }          return position;     }      public view getview(int position, view convertview, viewgroup parent) {          view view = convertview;          textview txt = null;          view = inflater.inflate(r.layout.test_layout, parent, false);          txt = (textview) view.findviewbyid(r.id.txtimg);            if(position >= txtdata.length) {             position = position % txtdata.length;         }           txt.settext(""+txtdata[position]+" :: "+position);           return view;      } } 

activity_main.xml

 <linearlayout      xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:id="@+id/layout1">      <gallery         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:id="@+id/mygallery"         android:layout_weight="1"/>  </linearlayout> 

screenshots :

enter image description here

these codes , screenshots of issue. , can check in screenshots , there set of 5 elements there in screen @ time , want change color of middle index.

please suggest me solution.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -