Android: EditText setError covers up standard AlertDialog buttons - android

I have a standard (not custom, no layout) AlertDialog with literally just an EditText as its view and two buttons (OK and cancel.)
When there's a problem with the input, I show an error message that ends up being three lines of text, which occludes the OK and cancel buttons. The error text does disappear once the user types something, but I'd sure like the cancel button to be visible.
Is there any (easy) way of changing the placement of the error text?

Unfortunately, not without some customization. The internal PopupWindow managed for the error display is called with showAsDropDown(), which let's Android decide where to display the view in relation to it's anchor (the error icon, in this case) and it will always be below the view unless there is not enough window space. You would have to create (albeit fairly simple) subclass of EditText that displays the internal PopupWindow using showAtLocation() instead.
Here's the link to the TextView source to hopefully help out if you want to try that. The setError() and showError() methods are what you would be after overriding.
HTH

Related

how to make UI controls appear properly in a dialog box

I want to collect user input from a dialog box caller alert1.
AlertDialog.Builder alert1=new AlertDialog.Builder(context);
LinearLayout layout1=new LinearLayout(context);//context is an object of type Context previously initialised to 'this'
layout1.addView(box1);//box1 is an EditText
alert1.setView(layout1);
alert1.show();
this however makes the edittext appear reallys small. but if i do this instead
alert1.setView(box1);
and get rid of the LinearLayout all together it appears right but i cant add anymore custom ui controls to this alert box. Can someone tell me where i'm wrong
its for target android 4.0
also i tried both orientations for the linear layout..
Try to set LayoutParams in the LinearLayout with the following code linearLayout.setLayoutParams(params);.

Android Custom Dialogue Box

Hi I want to make a custom dialogue box for my android application and want to populate it with buttons, check boxes and such kind of items.
I have followed the tutorial from android developers website, but that is not what I want, actually I want to customise the background and size of the dialogue box.
Please if any body could give me a head start, Plus I want to know when I design a background for that box, what dimensions and pixel numbers I use so that it may run the same in Galaxy Note, Galaxy S and tablets and other mobile phones running android.
Here is the picture of customised dialogue box. Like that I want to work out something.
Yes this is a good question. You must use a custom dialog with a transparent bg theme like these:
Dialog dialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog);
dialog.show();
where custom_dialog will be your XML for the dialog layout, and as far as dimensions go you should really test your app on a number of different screen resolution devices to ensure it displays as you want.
On occasion I have wanted to create a fully customized dialog such as the one you've shown.
When I had to do it, I fought for a while trying to make it a Dialog. In the end I found it was far easier to just wrap my dialog in its own activity, set it to theme transparent in the manifest, and make the layout xml file such that there was transparent space around the edges. That was the easiest way for me to get rid of all of the default dialog formatting (i.e. the frame that it comes in if you do it with the setContentView() route)
So while it is not technically a dialog any more, to the user it serves the same purpose.

popup windows in android?

Pretty new to android so excuse me if this is a really obvious question.
Say my application has a bunch of TextViews, each one showing the attributes of a certain product (name, price, etc). I have a button next to each of these TextViews labeled "modify".
How do I make it so that when I press the modify button next to a certain attribute, a popup window with a space to enter text into comes up so that the user can enter text into this box and then have the actual attribute listing on the original page change? Actually I just need a push in the right direction with creating this popup text field... not sure if there is already some built in functionality for this or if not, what would be the best way to create this kind of thing.
Thanks.
Why not have the modify button set TextEdit.setEnabled(true); and then change focus with TextEdit.setFocus? Note that both of these are inherited from view
If you really want a dialog you might want to looking into the AlertDialog.Builder. I know you can use it with buttons and radio buttons, but I'm not sure you can get it to work with a TextView.
Use a code like this for the input popup: Android dialog input text
In the positive button handler, set your edittext content programmatically like this:
myEditText.setText(value).
As simple as that. The only difference with a standard GUI framework is that you don't retrieve the value as a result of the popup function. Instead, you must provide an action handler.

Android dialog or floating activity off-center

Is it possible to have an Android Alert box or Dialog off-center? I have tried everything that comes to mind, including making a custom Dialog activity and theme (extending Android:Theme.Dialog), but I have not been able to move it from it's centered position.
Yes you can make the background translucent and fill the entire view, then nest a visible layout within that you can use layout_gravity="top|left" on.
A little off topic, but if you just want to display text, an easier way is to use a toast.
Toast toast = new Toast(new ContextThemeWrapper(getApplicationContext(), R.style.YourDialogStyle));
toast.setGravity(Gravity.LEFT|Gravity.TOP, 0,0);
PopupWindow? An example can be found here: http://www.anddev.org/how_to_create_a_popupwindow-t1259.html

iphone-style text edit on android

I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.

Categories

Resources