In spinner xml, I'm using:
android:entries="#array/cars"
where cars is list of numeric items.
The spinner automatically align values to left, and I can't find in xml/code how to change it.
You have to use a custom view here to give alignment to the Spinner values. Create a CustomView like this answer has created and add android:gravity to the TextView as right.
UPDATE:
Set the CustomView to your adapter using
adapter.setDropDownViewResource(android.R.layout.your_custom_created_view);
You can use TextAlignment on properties and select TextEnd,
or android:textAlignment="textEnd" on XML simple
You can try with spinner item text alignment right end :
view.textAlignment = View.TEXT_ALIGNMENT_TEXT_END
Related
I am using a custom adapter to populate a listview.The list item is made of 2 textviews and the result is the following:
Any reason why the textview appears faded?
you might not have set the textcolor and tht could be a reason. set the textcolor to the textviews to black and it would be done.
Maybe because you have made your textViews in listView row as enabled:"false" .
If so give your textView textColor = "#000000" and otherwise also give textColor
I have a Spinner where the text both inside the spinner and the choices when the spinner is expanded (drop down view) can be quite long depending on the locale. i set a custom view for both the spinner view and the drop down view that should allow the text lines to wrap,
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:minHeight="?android:attr/listPreferredItemHeight"
android:singleLine="false" />
and in the code,
spinnerPermission = (Spinner) layout.findViewById(R.id.permission_spinner);
ArrayAdapter<CharSequence> permissionAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.add_share_dialog_permissions,
R.layout.multiline_spinner_dropdown_item);
permissionAdapter.setDropDownViewResource(R.layout.multiline_spinner_dropdown_item);
spinnerPermission.setAdapter(permissionAdapter);
this works fine in android 2, but in android 4, the text in the drop down view still won't wrap,
although it's not clear from the image, the text in the spinner view does wrap correctly. I can't tell for sure, but it seems like the container around the drop down views is not constrained by the screen and expands off the screen to the right. That would prevent the text from wrapping, because as far as the TextView is concerned, there's plenty of space.
Here is the spinner's popup view in hierarchy viewer,
Any ideas?
I have solved this by custom layout where I have TextView inside LinearLayout. Both TextView and LinearLayout have fixed width 200dp. Then it wraps the text correctly both on Android 2.3 and 4.0.
CheckedTextView extends TextView, which has inputType, maxLines, minLines attributes.
Try applying android:inputType="textMultiline" attribute to your CheckedTextView, that should help.
Create custom layout, first Goto res folder->create New XML Layout file
eg: simple_spinner_layout.xml
link:http://justpaste.it/edit/2866098/aab2f5f3
Its work for me.
Plz vote for this answer if u have satisfied.
I have a list whose height is set to "fill parent". everything works fine but my last item in list touches the bottom of my screen. how can i get some space below my last list item.
You can add an empty view as footer: http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
AFAIK there's no way to do that only with XML, you can declare the footer in XML and inflate, or create programmatically
Here is a 3-liner to add a spacer programmatically:
View listFooter = new View(this);
listFooter.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, 70)));
listView.addFooterView(listFooter);
uhmm.. seeing that you don't want padding, print a blank line (or transparent text) on a textview located after your listview. Or print a "extra" item on your listview.
you could use the Space widget
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
can simply set the margin in the list ............
if need only bottom margin then use : android:layout_marginBottom=
I'm using a ListActivity with an ArrayAdapter. I have an array of Strings, and I want to put a divider after the 5th String in the list. Is there any way to do this? Sorry if there are duplicates, just did not find what I was looking for. Thanks in advance.
There is a hack.
Add a divider view at last in your list_item's layout file and give it an Id. Now in your custom adapter class,you can set that view's visibility depending on the position whether you want it to be shown or not,in getView() method.
A property of Listview will help you:
android:divider = (color or drawable)
And also
android:dividerHeight = (integer in dp)
I have a list view which has a footer.
It displays numbers and at the bottom is the total.
I want to be able to show the rows without a divider between them. OTOH I DO want a divider before the summary row.
Is there any easy way to do this?
You can set android:dividerHeight to 0 in your list.
Then use custom layout for footer in which you add divider by yourself. For example, that can be a TextView with no text, android:layout_height set to 2 and android:background set to some color.
When you have custom layout for the footer, just add divider on top of it. It can be for example View of hight 2dp and different background color.
I had to do this programatically, since setting android:dividerHeight="0dip" in the XML didn't work for me:
getListView().setDividerHeight(0);