itemprop = "text">
I know how to customize the spinner. It's a little different in my case. I can not modify my code more than ever. Normally, I am able to create a spinner which is accessible from all the activities in my app. I am trying to insert the icon with textview in the spinner drop down. I have a code here;
spinner.exam
spinner_row.xml
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: AddStatesFromChildren = "True" android: gravity = "center_horizontal" Android: padding = "5dp" Android: textColor = "#FFFFFF" Android: Textism = "17sp" & gt; & Lt; / TextView & gt; & Lt ;! - I can not use relative layout here if I use it [java.lang.ClassCastException: android.widget.ImageView can not be inserted for Android. Without Layout I can not implement ImageView I'm stuck here
My Activity Category;
Public class extends the Base_Activity activity {@Override Public Boolean onCreateOptionsMenu (menu menu) {getMenuInflater () increased (R.menu. Main menu); // int Flags = R.RA.Flag; Last spinner spinner = (spinner) menu .getItem (0) .getActionView () .FindViewIID (RID spinner); ArrayAdapter & LT; CharSequence & gt; Adapter = Arrayadaptor.Creatofrom Resource (This, R. Ratha Language, R. Late Spinner_RO); Spinner.setAdapter (adapter); Spinner.setOnItemSelectedListener (New AdapterView.OnItemSelectedListener) {
What I want to do is create custom adapter so that I can put the image with TextView in the spinner list. In general I have tested in several tutorials, I think this is because I am making the spreader in the Create Option menu () constructor.
U can take a look at this
code snippet
// spinner header navigation data navSpinner = new ArrayList & lt; SpinnerNavItem & gt; (); navSpinner.add (New SpinnerNavItem ("local", R.drawable Ic_location); navSpinner .add (New SpinnerNavItem ("My Places", R.drawable.ic_my_places)); navSpinner.add (New SpinnerNavItem ("Checkin", Ardravable.IC_checkin)); Navispinner.ed (New SpinnerNVIT ("Latitude ", RWYAIL_Litidid)); // title drop down adapter adapter = new title navigation adapter (getApplic etien contact (), nsppinner); getView ()
and getDropDownView () to TitleNavigationAdapter
View public getView (integer position, seeviewview, ViewGroup parent) {if (convertView == null) {LayoutInflater mInflater = (LayoutInflater) context.getSystemService (activity. LEOUT_INFLATER_SERVICE); Convertview = mInflater.inflate (R.layout.list_item_title_navigation, null); } ImgIcon = (ImageView) Convert View.findViewById (R.id.imgIcon); TxtTitle = (TextView) ConvertviewFindIDxtTitle; ImgIcon.setImageResource (spinnerNavItem.get (status) .getIcon ()); ImgIcon.setVisibility (View.GONE); TxtTitle.setText (spinnerNavItem.get (status) .getTitle ()); Return Convertview; } @Override Public View getDropDownView (integer position, view convertView, ViewGroup parent) {if (convertView == faucet} {LayoutInflater mInflater = (LayoutInflater) context.getSystemService (Activity.LAYOUT_INFLATER_SERVICE); Convertview = mInflater.inflate (R.layout.list_item_title_navigation, null); } ImgIcon = (ImageView) Convert View.findViewById (R.id.imgIcon); TxtTitle = (TextView) ConvertviewFindIDxtTitle; ImgIcon.setImageResource (spinnerNavItem.get (status) .getIcon ()); TxtTitle.setText (spinnerNavItem.get (status) .getTitle ()); Return Convertview; }
Download that code and you are good to go
Comments
Post a Comment