You need to implement a custom Adapter and define a custom layout for the list items Check this tutorial UPDATE Try the following. I haven't tested the code but I think it should work like that public class MyCustomAdapter extends ArrayAdapter{ private String mIcons; public MyCustomAdapter(Context context, int textViewResourceId, String objects, String icons) { super(context, textViewResourceId, objects); mIcons = icons; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { return getCustomView(position, convertView, parent); } @Override public View getView(int position, View convertView, ViewGroup parent) { return getCustomView(position, convertView, parent); } public View getCustomView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater=getLayoutInflater(); View row=inflater. Inflate(R.layout.
Spinnerrow, parent, false); TextView label=(TextView) findViewById(R.id. Functie); label. SetText(getItem(position); ImageView icon=(ImageView)row.
FindViewById(R.id. Icon); String uri = "@drawable/a" + mIconsposition; int imageResource = getResources(). GetIdentifier(uri, null, getPackageName()); icon.
SetImageResource(imageResource); return row; } }.
You need to implement a custom Adapter and define a custom layout for the list items. Check this tutorial. UPDATE Try the following.
I haven't tested the code but I think it should work like that. Public class MyCustomAdapter extends ArrayAdapter{ private String mIcons; public MyCustomAdapter(Context context, int textViewResourceId, String objects, String icons) { super(context, textViewResourceId, objects); mIcons = icons; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { return getCustomView(position, convertView, parent); } @Override public View getView(int position, View convertView, ViewGroup parent) { return getCustomView(position, convertView, parent); } public View getCustomView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater=getLayoutInflater(); View row=inflater. Inflate(R.layout.
Spinnerrow, parent, false); TextView label=(TextView) findViewById(R.id. Functie); label. SetText(getItem(position); ImageView icon=(ImageView)row.
FindViewById(R.id. Icon); String uri = "@drawable/a" + mIconsposition; int imageResource = getResources(). GetIdentifier(uri, null, getPackageName()); icon.
SetImageResource(imageResource); return row; } }.
Yep, a linearlayout with the text and the icon, a custom adapter, and a couple of getText() and setText() accessory methods. There's another thorough tutorial (for lists, but the same concept) here: anddev. Org/iconified_textlist_-_the_making_of-t97.
Html – Aleadam Apr 21 at 12:53 I've tried the tutorial, but I'm still kind of tangled with my two Arrays... would you mind helping me? Thanks a lot in advance – Hannelore Apr 21 at 13:12 What is the problem at the moment? As I can see in you edited question, you're already accessing both array from within your adapter.Label.
SetText(jobsposition); and String uri = "@drawable/a" + jobsidposition; – Flo Apr 21 at 14:04 I don't know how to pass the array with icons to the arrayadapter. I can pass one array, put not two... When I run this code I get the following error: pastebin. Com/5JRPEnLt – Hannelore Apr 21 at 14:13 1 I think you have to implement this behavior in the getView() method of you adapter.At the moment getView() and getDropDownView() both call getCustomView(), so the items always look the same regardless if the spinner is in drop down mode or not.
So in your case each of the both methods needs its own implementation.GetDropDownView() can simply call the getCustomView() method, but in the getView() method you have to hide the icon. – Flo Apr 217 at 8:37.
In my app, I have a Spinner, that can be filled with two Arrays of Strings, stored in my values/strings. Depending on the state of two RadioButtons, the values from the correct Array is selected and my Spinner gets filled. For each Array of Strings, I have an Array of Icons which have the same size.
All of my icons start with an "A" and are followed by a number. I can't change this, it's stored like that in the database. I have an Array in Strings.
Xml with all the numbers I require to draw the icons. All the actual icons can be found in the drawable resource folder. Now I want to show the corresponding item next to the String from the list which was selected by the Spinner.
When an item gets selected, I just need to see the text. I have searched the Internet for a good tutorial, but with what I have found I have not succeeded in doing this. I'm just beginning in Android programming so I think I need a little help.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.