setAdapter() in Android Spinner removes the custom background drawable - android

Here is the background drawable image of my spinner, when I've not set adapter :
Here is the xml :
<Spinner
android:id="#+id/cats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="50"
android:gravity="bottom"
android:background="#drawable/bgspinner"
android:textSize="12sp" />
But, when I set adapter, the background looks like has been overridden:
and here is the java code :
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.newcardialogitme, lables);
cat.setAdapter(dataAdapter);
But when I do this with custom layout.xml, background image of the spinner is overridden! .
Please help me in understanding this.

Use custom adapter and in getview methosset background to parent view as below. It will work.
parent.setBackgroundResource(R.drawable.spinner_background);

Have you checked your ..
R.layout.newcardialogitme file..
because your spinner taking that layout's background..
please set its background to transparent color..
then you will have you background..
Appreciation welcomed

Related

How to make the list of spinner items rounded? Not the spinner itself, but dropdown list

I want to display the items of spinner in rounded rectangle list, not the default rectangle. I don't mean the spinner itself, but the list which falls after arrow is clicked. Is there a way to do this? The attempt to make custom_rounded_layout and attaching to it adapter changed the layout of each item, not the list itself. However, I want the list itself to be rounded, not the items. Right now the list is the default one. I want to make the corners of the list a bit rounded. Thanks in advance
Create a layout file with a rounded background textview like this:
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="#dimen/size_40"
android:background="#drawable/bg_round"
android:gravity="center_vertical"
android:id="#+id/ssdsd"
android:layout_margin="16dp"
android:padding="10dp"
android:text="#string/app_name" />
Now pass this in the spinner adapter
Spinner spinner = findViewById(R.id.yourSpinner);
spinner.setAdapter(new ArrayAdapter<String(this,R.layout.spinner_item,R.id.ssdsd,list));
To change the popup background, use this on your Spinner xml code:
android:popupBackground="#drawable/bg_round"
NB: You might need to adjust padding and margin to make it look good, this is just an idea of how you can do it.

Setting color for an item of a view list in android

I'm trying to change the items color on the list view.
I tried that , but its not working:
android:textColor = "#FFFFFF"
<ListView
android:id="#+id/listViewToDo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:textColor="#FFFFFF" >
</ListView>
To change listView items color, you should implement a custom adapter and pass it a view.
We can change the view attributes programmatically from the getView() methods which returns a View object.
To create a listView you'll need one xml file to represent a row, right?
So, if you want the same color for all of the rows, you could just set android:textColor="#FFFFFF" there.
Hope it helps.

How to change Spinner drop down image icon?

I want to change the default spinner drop down icon also want to change the background of it, by using which property I can do that?
I am having following spinner code:
<Spinner
android:id="#+id/security_ques"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
style="#style/spinner_style"
android:prompt="#string/prompt" >
</Spinner>
please give any solution on it
See this link for custom spinner drop down box.
They have created customized xml layout for spinner and called that layout to the spinner using these code
Spinner mySpinner = (Spinner) findViewById(R.id.spinner_show);
mySpinner.setAdapter(new MyAdapter(this, R.layout.custom_spinner, spinnerValues));
use it in your xml
android:background="#drawable/your_imagename"

Android: change text color dynamically in listview

I have a listview in an Android application with a row.xml file for layout:
String[] from = { "Field_1", "Field_2", "Field_3" };
int[] to = { R.id.Field_1, R.id.Field_2, R.id.Field_3};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.row, from, to);
final ListView listView = ( ListView ) findViewById(R.id.values);
listView.setAdapter(adapter);
In row.xml, Field_3 is:
<TextView
android:id="#+id/Field_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:textColor="#color/red"
android:layout_marginRight="150dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="25dp"
android:textStyle="bold"
android:textSize="14sp" >
</TextView>
Basically, text show in TextView with ID Field_3 is red, but I want, in some cases, to make the text color green.
I tried with HTML formatting, but it doesn't work.
Is there a way to dynamically change the color in array or in simpleAdapter?
You can write your own Adapter which behaves like you want.
Just override getView method and there change color
Something like this:
view = layoutInflater.inflate(R.layout.item, null);
view.findViewById(R.id.Field_3) and here you can do anything
As #megatron answered so, you should use a custom adapter which gives you pretty much freedom. And If you want to do it in this way, you can take a look to Vogella's tutorial about ListView and Custom adapters.
http://www.vogella.com/articles/AndroidListView/article.html#adapterown

Set a progress spinner inside the AutoCompleteTextView

I'd like to insert a progress spinner in AutoCompleteTextView while another class performs the autocomplete function.
I read about the frame Layout ed fixing it in the EditText but the question is:
How to set the progress spinner? And how to control it?
Use this in the layout where you want to display the ProgressBar. You can set the visibility, View.VISIBLE, View.GONE to make it visible and invisible.
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.ProgressBar.Small"
android:layout_marginRight="5dp" />

Categories

Resources