[You can perfectly see the problem here, the drop downlist opens from the top of the spinner and not from the bottom and I don't know what to do, couldn't find any solution on google either, please help me] sorry for external image link, for some reason it wont load the picture here..
here is my spinner code:
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rgGender"
android:entries="#array/months_array"
android:textAlignment="center"
android:id="#+id/spMonth"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"/>
This would happen if the item which inflates the spinner is close to the bottom of the screen.
Since the spinner would not have enough room (or just barely enough room) if inflated downward, it is inflated upward instead. Try putting the spinner higher (vertically) in the layout.
It depends on Screen size, If you test it on other device it will show at down/up.
I suggest you to test it on different devices.
you can use custome adapter if you want
<Spinner
...
android:overlapAnchor="false" />
Please check this answer and this answer
Related
I know this question is repeated but I don't get the Proper solutions.
I want to bring arrow closer to the Spinner (That means i want to decrease the width of spinner and decrease the space between text and down arrow) I have used default spinner. How can I do that? Please, guide me to get Solution.
Here is the XML code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/relativeLayout15">
<Spinner
android:id="#+id/languageDropdown"
style="#style/SpinnerTheme"
android:layout_width="66dp"
android:layout_height="wrap_content"
android:entries="#array/Languages" />
</RelativeLayout>
As i am understanding your question, many time we face requirement to customise spinner UI and it is too tough to achieve this. I generally use this solution for such situations:
Solution: Hide your actual Spinner and show a TextView which just looks like our desired Spinner, Please have a look at below image for better understanding:
In above image I have created a phone number field where I am getting country code from user using Spinner. I created a TextView having text as country code with drawable[right] of down arrow. Please check below XML code for better understanding:
In above image Spinner width is 0dp so your Spinner will not be visible. Just remember one thin you have to handle click event of TextView and call performClick() method for Spinner. Please refer below image for this code:
On the click event of your TextView, just follow below way:
textViewLabelCodeRegister.id -> {
spinnerCountriesRegister.performClick()
}
That's It.
Make PopupWindow instead of Spinner.
I have a form in a DialogFragment that includes a spinner. I don't think I can port the spinner options out to a new activity (e.g. customisable ListView etc.) as it will close the DialogFragment, so I'm using the spinner embedded into the DialogFragment (screenshot 1). There is nothing unusual about how I'm populating the spinner with an ArrayList and adapter.
<Spinner
android:id="#+id/breedingcodes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip" />
Functionally it works fine and the spinner options appear and are selectable, but looks terrible as it only uses half the screen (see screenshot 2), anchored to the position of the spinner in the DialogFragment. Is there anyway to force it to use the full screen, as in the 3rd screenshot with Breeding evidence title? I've tried fiddling with layout_height="match_parent" etc. - no joy.
App is developed for min SDK_10, compiled for SDK_23, build tools 23.0.3.
You can either create your own dialog and style it as you want, or just use
android:spinnerMode="dialog"
as attribute in spinner. See docs here
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
you could try the above in your program to get fullscreen spinner :)
I am working with the simple ListView. Need to make this ListView round (not the every list item round, but the ListView itself). So for this purpose I use shape xml-file. It looks like that:
The problem appears when I need to change color of the items. This color overlaps border of the listview. And it looks something like that:
As you can see, the listView is square again, not rounded. How can I prevent this? Couldn't found the solution though it seems a pretty much common thing to me.
If you want to add space around you list item add in you list item layout..
android:paddingTop="2dp"
android:paddingRight="2dp"
android:paddingLeft="2dp";
android:paddingBottom="2dp";
or
android:padding="2dp"
Use padding in listview..
android:padding="5dp"
The first time I noticed this was with AlertDialogs putting the entire message on the first line, even when I specified a new line("\n"). On ICS it displays the correct way, but for the life of me, I couldn't get it to work on GB.
Recently I've run into it again. I don't see any reason for it working fine on ICS but not GB and below.
EXAMPLE Project
Heres an example project with a textview, alertdialog, and two standard textviews.
https://github.com/T3hh4xx0r/Text-Example
EDIT
Heres the original question I asked. Seems the problem is more than I originally noticed though.
Android AlertDialog not displaying entire setMessage on certain devices
/EDIT
Here are visual examples of what I mean.
Even specifically setting multiple lines for the textView, the text is still one line, but with extra blank lines below.
Here is the layout that the alertdialog is using to create your view:
<!--
This layout file is used by the AlertDialog when displaying a list of items.
This layout file is inflated and used as the TextView to display individual
items.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/primary_text_light_disable_only"
android:gravity="center_vertical"
android:paddingLeft="14dip"
android:paddingRight="15dip"
android:ellipsize="marquee"
/>
As you can see the ellipsize is set to marquee, so I don't believe it was ever written with the intention to allow multilines.
There is a bug open at the moment that ellipse dots are never shown: http://code.google.com/p/android/issues/detail?id=10554
Therefore it is acting correctly.
If you want it to go onto multiple lines, create your own layout file and pass that to your dialog, that way you have more control anyway.
I have spent literally two days trying to sort this issue. If anyone could help I would be massively appreciative.
What I'm trying to achieve:
Have a ListView, whereby the player can add new entries (players), through a text field (for the player name), and then a submit button. In each field of the ListView, I display the player name, and then two ImageButtons. One with a male symbol, and one with a female symbol. The male symbol is toggled by default, and the user can set the player as being male or female by toggling either the male button or the female button. Finally, once the user moves onto the next screen (a new activity), the application will save the player names and the attached sex to some form of storage and proceed to the next activity.
What I have achieved:
I have a simple array adapter, which upon the player adding a new player name to the list, I run the notifyDataSetChanged() on it. The adapter also is set to use a custom row layout file. Inside the layout file, it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="fill_parent" android:id="#+id/relativeLayout1" android:layout_marginTop="5dp">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/playerName"
android:layout_centerVertical="true" android:text="Derp" android:textStyle="bold" android:layout_marginLeft="5dp" android:textSize="22dp" android:textColor="#color/male_blue"></TextView>
<ImageButton android:layout_height="60dp"
android:layout_width="60dp" android:onClick="maleClickHandler"
android:src="#drawable/male_icon_settings" android:id="#+id/buttonA" android:layout_alignParentRight="true" android:layout_marginRight="65dp"></ImageButton>
<ImageButton android:onClick="femaleClickHandler"
android:layout_height="60dp" android:layout_width="60dp" android:id="#+id/buttonB"
android:layout_alignParentRight="true" android:layout_marginRight="5dp" android:src="#drawable/female_icon_settings"></ImageButton>
</RelativeLayout>
</LinearLayout>
The two buttons on each row reference to methods in the class file. Here is my code for this:
public void maleClickHandler(View v) {
RelativeLayout vwParentRow = (RelativeLayout) v.getParent();
ImageButton maleButton = (ImageButton) vwParentRow.getChildAt(1);
maleButton.setImageDrawable(getResources().getDrawable(
R.drawable.male_icon_selected));
vwParentRow.refreshDrawableState();
}
public void femaleClickHandler(View v) {
RelativeLayout vwParentRow = (RelativeLayout) v.getParent();
ImageButton femaleButton = (ImageButton) vwParentRow.getChildAt(2);
femaleButton.setImageDrawable(getResources().getDrawable(
R.drawable.female_icon_selected));
vwParentRow.refreshDrawableState();
}
I haven't yet implemented any inter-connectivity between these two buttons, to allow only one to be active at a time, or to even untoggle one, since I think I might be taking the wrong approach entirely.
The problem:
Upon adding new entries to the list, AFTER toggling one and/or the other male/female buttons, things get really buggy, and the male/female toggled icon might move as it should, along with the attached player string, or more likely, those toggled will stay on that first row (array position 0 of the list), or even move into the second list position, AND copy themselves as being toggled onto the row above.
How you can help...?
I have attached an image below of my screen, from the emulator, to help illustrate my points
Screenshot!
I think that I might need to use some form of custom adapter; I have done so much reading around on the subject, but I can't find anything relevant to what I am trying to achieve, so if you could point me in the right direction, or even try and put together the most basic solution to this type of problem, I would be very grateful.
Finally, when I get this working, which form of storage would be best for storing player names, and their sex? I would like the user to be able to keep the player list after they quit the application and restarted it.
Thanks for any help! :)
You will need to use a Custom Adapter, which in itself should be able to track the male/female flag for each of it's entries.
Your method will not work since the state of the buttons are managed by the getView method of the adapter. Even if you change them by digging through the children, the next time when the getView method is called, it's going to mess up things.
A lot of this depends on how many players you expect to have in your game. If it's a number that would likely fit on one screen (or very close to it), the ListView is actually unnecessary. ListViews and adapters aren't really a convenience method as much as they are a tool to improve performance. They only keep in memory what is on the screen and recycle old, already-displayed Views for new rows when you scroll--this is why some of your button states are being copied to different rows.
There are a couple of ways you could fix this:
You could write a custom adapter yourself as Kumar Bibek suggests. In this adapter, you would want to override the getView() method to make sure each button has the correct state each time the method is called.
You could also simply use a ScrollView populated with a few of your rows manually if you don't have enough data to warrant using a ListView. This way you wouldn't need to worry about your rows being recycled and button states being out of wack.
In addition, you might want to look into using a RadioGroup for the gender selector (I can't think of a much better use for radio buttons since they are made to be mutually exclusive).
Also, the outer LinearLayout in your row XML file looks unnecessary.
As far as storage, you could either use an SQLite database or SharedPreferences. SharedPreferences requires no setup, but I feel like an SQLite database is more suited to your needs.