Android. Radiobutton text won't display correctly - android

I have the below xml code which i use to display inside a Dialog. The problem is that the letter "E" in "Easy" is displayed under the radio button itself. So it's not visible. Why is that? The rest are shown correctly, on the right side of each corresponding RadioButton.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radioBtnEasy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Easy"
android:layout_weight="1" />
<RadioButton
android:id="#+id/radioBtnMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="Medium"
android:layout_weight="1" />
<RadioButton
android:id="#+id/radioBtnHard"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hard"
android:layout_weight="1" />
</RadioGroup>
EDIT
At Padma Kumar's request, i post the rest of the code. This is how i display the dialog. I made the dialog's width to fit the screen's width, and not wrap around the content.
I removed this, but it still displayed the Easy text incorrectly.
//Define a new dialog window
Dialog dialog = new Dialog(this);
//Load the predefined layout onto this dialog
dialog.setContentView(R.layout.new_session_dialog);
//Set title of dialog
dialog.setTitle("Create new session");
//Set the width of the dialog to fill the width of the screen
dialog.getWindow().setLayout(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
//Show the dialog
dialog.show();

use the android:ems attribute it but manage your text on all density device

The 0dp width is most likely the issue,
Otherwise if only the first character "E" is not being displayed, put a space before Easy.
Ex)Instead of "Easy" put " Easy"

Thanks for posting this question. I ran into the same problem: the icon in the first radio button stomped on the first letter in the text following it. I am using the Android 1.6 emulator. After I install my app, start my app and display the radio group, I see the problem. However, when I use Back key to take me back to the Home screen and start my app and display the radio group again, I don't see the problem!

Try to remove layout_weight=1 first and put fill_parent on RadioButton width. Then do necessary adjustment.

Related

android studio - How do I resize buttons based on text?

I'm making two buttons.
if One button is clicked, the other button's text is changed.
I coded initial status using setText
mBtn.setOnClickListener(this);
mBtn.setText("Connect");
and changing text using
mBtn.setText("Disconnect");
In this case, button's length is fixed initial length.
What can i do?
use this on your layout it will work. remove fixed width first.
android:layout_width="wrap_content"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Connect"
android:padding="5dp"
/>

Changing text while pressing button android studio

I've tried a tutorial on youtube but it doesn't work,when I click the button nothing happens.
When I press the button I want to Change the layout activity and also to be set on the new layout one random text from lets say other 10 and on this current layout I wanna have the button which will randomly change the first text to another one.
Here is what codes I've used and didn't worked out.
#I can't add the codes because It doesn't let me post it here..it says something like isn't valid but you see everything in the picture,so I did all that code and when I press on my button It doesn't doing anything,what can be the problem?and If you have any idea or if you know any tutorial to help me achieve what I said I want to do upper I would appreciate really much
#as you can see there is a string option which should give me one text of all of them when I click my button,but it doesn't
sorry for image but it seems like those codes aren't good
<LinearLayout
android:layout_width="332dp"
android:layout_height="184dp"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:layout_marginTop="48dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/buttonsports"
android:layout_width="match_parent"
android:layout_height="129dp"
android:background="#drawable/ft"
tools:layout_editor_absoluteX="115dp"
tools:layout_editor_absoluteY="291dp" />
<TextView
android:id="#+id/sports"
android:layout_width="216dp"
android:layout_height="117dp"
android:text="TextView"
tools:layout_editor_absoluteX="95dp"
tools:layout_editor_absoluteY="246dp" />
</LinearLayout>
this is how big my text box is,the "sports" is the id for TextView which is "abc"
In your xml you have a LinearLayout for which you have set the height to:
android:layout_height="184dp"
and inside there is a Button with height:
android:layout_height="129dp"
So for the TextView below there is left maximum 55dp but you set:
android:layout_height="117dp"
This means that at least half the TextView is not visible.
In your code you set a random text to the TextView when you click the Button.
You say that nothing happens.
Is there a case that the text is being set but you can't see it because the TextView is mostly hidden?
Change the heights of the views and you will find out.

How can I use a custom font in the input area of an input method?

We're developing an app where we need to use a custom font (a Typeface loaded from the app's assets) in an EditText. The Android input method docs state the following:
When input focus moves into or out of an editable text field, Android shows or hides the input method (such as the on-screen keyboard) as appropriate. The system also makes decisions about how your UI and the text field appear above the input method. For example, when the vertical space on the screen is constrained, the text field might fill all space above the input method.
It's the part in bold that is tripping us up. The phrase “the text field might fill...” appears to be misleading, in that the text field that's used is not the EditText that we set up with our custom font. (NOTE: the answers so far all explain how to set a custom font in an EditText. We already are setting a custom typeface in the EditText. Please read the question carefully before answering.) Here's a screenshot with the input method hidden:
Here's what happens when the soft keyboard is showing and vertical space is constrained:
As you can see, the font in the text field above the input method is not our custom font (I'm guessing it's the system's default Roboto font). This is happening for every soft keyboard we've tried as the input method.
I want to emphasize that when space is constrained, this view above the keyboard is generated internally by the system, not by any of our code.
The main question is: Is there a way (and, if so, what is it?) to control the appearance of this (for lack of better terminology) proxy view—at a minimum to get it to use our custom font?
It would be an added bonus if we could also control the layout and appearance of the entire proxy area above the keyboard (including the "Done" button). We are using a variation of the technique described in this thread to have our activity use a locale different from the one set in the system, but the activity's locale clearly isn't being applied here. (If it were, the button would be on the left and would read "בוצע", as does happen if I change the device's locale to Hebrew. [EDIT: I can get the correct button label by using the android:imeActionLabel attribute on the EditText. However, I don't know how to control the layout directionality.])
EDIT Per request, here's how I'm constructing my dialog (relevant parts excerpted from a DialogFragment):
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dlg = new Dialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar);
dlg.setContentView(R.layout.edit_note_dialog);
mAnimator = (ViewAnimator) dlg.findViewById(R.id.animator);
final Typeface hebrew = SystemData.getHebrewFont();
mNoteEditor = (EditText) dlg.findViewById(R.id.note_field);
mNoteEditor.setTypeface(hebrew);
// etc. (setting fonts for other elements, adding listeners, etc.)
}
And here's the layout:
<?xml version="1.0" encoding="utf-8"?>
<ViewAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/animator"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="#string/loading" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#android:color/black"
android:gravity="center"
android:text="#string/edit_note_title"
android:textColor="#android:color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/citation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:background="#android:color/black"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="16sp" />
<LinearLayout
android:id="#+id/actions"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp" >
<Button
android:id="#+id/cancel"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:gravity="center"
android:minWidth="32dp"
android:text="#string/cancel"
android:textSize="#dimen/nav_interior_item_size" />
<Button
android:id="#+id/close"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="center"
android:minWidth="32dp"
android:text="#string/save"
android:textSize="#dimen/nav_interior_item_size" />
</LinearLayout>
<Button
android:id="#+id/undo"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_margin="5dp"
android:text="#string/edit_note_undo"
android:textSize="#dimen/nav_interior_item_size" />
<Button
android:id="#+id/redo"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="5dp"
android:text="#string/edit_note_redo"
android:textSize="#dimen/nav_interior_item_size" />
<EditText
android:id="#+id/note_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/actions"
android:layout_below="#+id/citation"
android:focusableInTouchMode="true"
android:gravity="top"
android:hint="#string/edit_note_hint"
android:imeActionLabel="#string/done"
android:inputType="textMultiLine|textNoSuggestions"
android:lineSpacingMultiplier="1.2" />
</RelativeLayout>
</ViewAnimator>
It would be simple if you had an instance of InputMethodService.
There is a way to set a theme or even set extracted view.
The problem is you have to create a custom implementation of Input Method and users will have to select it in the system settings.
Update:
You can try with:
android:windowSoftInputMode="adjustResize"
make the view scrollable
or
use IME_FLAG_NO_EXTRACT_UI
set an OnEditorActionListener on the EditText to have an action button on the keyboard.
create custom layout or hide/show elements when screen's height is too small. For example hide buttons at the bottom and show buttons on right side. It can look similar to the default extract view.
layout listener for the dialog or EditText:
mViewContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
//unregister the layout listener if needed.
int heightPixels = mViewContainer.getHeight();
Resources resources = mContext.getResources();
int heightDip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, heightPixels, resources.getDisplayMetrics());
if (heightDip < MIN_HEIGHT) {
mBottomButtons.setVisibility(View.GONE);
mSideButtons.setVisibility(View.VISIBLE);
} else {
mBottomButtons.setVisibility(View.VISIBLE);
mSideButtons.setVisibility(View.GONE);
}
}
});
Changing the visibility to GONE will request relayout and the listener will run again what can lead to a loop.
The only way I can see is to disable the fullscreen editing mode for your EditText that automatically kicks in when your EditText is not tall enough.
mNoteEditor.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
You can fix the dialog resizing issues with
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Your dialog layout should probably be enclosed in a ScrollView.
I think as other have stated this is unfortunately up the IME and may not be possible through supported APIs.
Beware, hacky and untested solution incoming:
Digging through the Android source code, I found that every IME contains an implementation of AbstractInputMethodService. Android provides a standard implementation (android.inputmethodservice.InputMethodService) which if you look at, has a public setExtractView method, and an onCreateExtractTextView method, which inflates com.android.internal.R.layout.input_method_extract_view.xml, which in turn contains com.android.internal.R.id.inputExtractEditText! So a hacky solution would be to hope that most of your customer's IMEs' InputMethodServices use this same XML (which as far as I can tell, has been in Android for a while), and you can attempt to grab a reference to this EditText by it's ID and change it's typeface. Unfortunately I'm not sure offhand where in the view hierarchy/window the views of an InputMethodService are added, and if they're accessible from your app/activitys process.
Source for InputMethodService:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/inputmethodservice/InputMethodService.java
Source for the layout XML:
https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/input_method_extract_view.xml
If you really want to get yourself in trouble, perhaps there's a way to get a reference to the IME service itself, and use reflection to alter the extracted view. The standard InputMethodService holds a package-private reference to mExtractEditText :)
I know not the answer you're looking for but perhaps it'll put you in the right direction...or some direction at least.
If you have a single editable element on your Dialog, how about handling orientation changes and
in case of Portrait orientation, show the Dialog
in case of Landscape orientation, show a fullscreen Fragment with the EditText and Buttons (as others have stated; disable fullscreen editing mode for the EditText), request focus for the EditText, show Keyboard.
in case of orientation switching dismiss Dialog / show Fragment with the already entered text (and vice versa)
This might be conceptually good because if the user wishes to enter text, he/she will always end up in a fullscreen editing layout in Landscape orientation. And since there is only one editable view in the original Dialog, you don't explicitly need the Dialog to select anything else to edit (another EditText for example).

Android GUI: what are the good UI patterns for entering an integer number?

There are two numbers constantly displayed in my UI. I need the user to be able to specify those numbers. In a desktop app I simply use 2 spinbuttons, and can beat it (I guess). However, there are problems with this in Android (I am targeting Android 3-based tablets).
First of all, I've tried NumberPicker widget, but it simply does not show itself properly (I've asked a question about it, but no response so far).
Then I've tried some 3rd-party numberpicker implementations one cand find on the Web, but for various reason didn't like neither of them. Some of them are too large to fit the side panel I'm squeezing controls into, some are just ugly (and too small, probably), and all of them automatically grab input focus causing the keyboard to show every time I open this side panel.
There is another option - only show the uneditable label with a number on the panel, and show popup window with some numberpickers in it. Apart from me not knowing how to implement such a popup (just learning), how do I decorate the label so that the user understands he can tap it to edit?
Perhaps, there are better solutions for this problem? I took a look at some apps from Google Market, and they all seem to either use huge NumberPickers at the center of the screen (and I need as much of the screen as possible clear), or a popup with the same huge Numberpickers I don't particularly like.
Can you suggest anything else? Thanks in advance!
There are two different issues in your question:
For the number picker for eaxmple in my case I have created a simple tool. You can just put a button with the text "-" then a textview and then a button with "+". You put it in a linear layout and t can be vertical or horizontal. If you want it you can make it very small. For example here is what I have wrote but you can try playing with the options to see which is better for you.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical" android:id="#+id/linearLayout1"
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content">
<Button android:id="#+id/button22" android:layout_gravity="center"
android:layout_weight="1" android:text="+" android:gravity="center"
android:layout_width="30dip" android:layout_height="30dip"></Button>
<Button android:id="#+id/button11"
android:layout_gravity="center"
android:layout_weight="1" android:text="-"
android:gravity="center" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_height="30dip" android:layout_width="30dip"></Button>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1" android:orientation="vertical">
<Button android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="30dip"
android:text="0" android:id="#+id/quantidad"></Button>
</LinearLayout>
then you can add onClick listeners on the buttons and setup to increase or decrase the text displayed in the text view.
As for the keyboard well if you use that example you not need it but if you use an edittext then you can setup an option for the keyboard to be hidden in the manifest: you can see the option here http://developer.android.com/guide/topics/manifest/activity-element.html

Split button text into two sections

I am trying to port my WP7 app to android.
Does anyone know how I can layout the text on a single button so that some text appears aligned left and other text appears aligned right? (See below). I need access to be able to dynamically change the percentage number on the right side using code but the text on the right is just static.
Anyone know the answer to this?
The image is here:
http://i.imgur.com/zW7YV.png
Yes you could make it two buttons.
Remove all padding and margin from between them.
Set the same background drawable.
And just ensure when the left is clicked it invokes the right's onPress method (so it looks as if they depress together).
Or wrap the buttons/imageviews/textviews in a layout and perform the onClick on that.
I would use a RelativeLayout for this.
<RelativeLayout
android:width="fill_parent"
android:height="wrap_content"
android:clickable="true"
android:background="#18a2e7"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_align_parentRight="true"
android:text="0%" />
</RelativeLayout>

Categories

Resources