I have an activity with a UI with many elements (Radio, EditText, etc.). When I change the text in an EditText I want that UI back at its starting state.
I tried to kill and restart the activity but with poor results. Any ideas?
Thanks
I would try calling setContentView again with a new view or with the xml file you used for rendering your activity in the first place
Once you get the value you need from your editText, you can reset it using
editText.setText("");
You can similarly programatically control other parts of your UI too.
Why not put all of the reset stuff in one function and simply call it when you need to:
public void resetUI()
{
//reset UI programatically
}
You could add a listener to the EditText view and when the text is what you want it to be you can just programmatically empty any TextView's, EditText's, reset any radiobuttons or radio groups to their default values. No need to restart the activity. Just write a helper method that resets your view "manually". Using setContentView() could also work although I haven't tried it and you might have to setup your complete view again with listeners and such.
Related
I'm trying to design my LoginActivity to look like my LoginController in iOS. Is there a way to make an activity transparent, or do I need to use a fragment? Thank you!
// My Design
You can achieve this through multiple ways
Create an activity and make its background as transparent in the layout.(Not recommended)
Create an alert dialog within the activity and make the alert dialog background as transparent
Create a dialog fragment make its layout transparent and open it from the activity.
Create a view stub within the same activity layout and inflate the view when required. (Handling back press events might be a difficult task here).
Although the right way would be to create an alert dialog within the activity or creating a dialog fragment or create a view stub. Create an alert dialog if you don't have much events or elements within the dialog since its easy and efficient than creating a dialog fragment for a little dialog. Creating a view stub would be the most efficient way since it simply inflates the view which takes less amount of resource. But don't go with creating an activity for this dialog which is resource intensive and not the correct way.
I am having a problem that I have edittext and spinner inside an expandableListView and after writing something in editText when I hide the soft keyboard my expandablelistView gets recycled to its previous state and all the values which i changed gets Lost.
The main problem with my code is that my view is getting generated through an xml page which is being made in server and so i cannot tell that whether an editText going to come or not.
I am retaining value using hashMap and its getting retain in expand and collapse but the only problem I am facing is that whenever soft input keyboard is opened and then closed my expandable gets recycled.
I think if in my adapter I can know about the soft input keyboard status like it is shown or hidden then I may retain the status of it.
you have to preserve the state of the EditText in the adapter. for example, add a change listener and write it to a model object/DAO. you should read it from your model in the onCreateView().
if you don't know what elements are comming it will get hard to store all information. you could search the tree for EditText.class.equals(view.getClass()) and save the state in a map maybe using the id from your data model or items of the adapter.
you should not care about keyboard presence if you do all things right
I have a problem that the ViewWillAppear method for a UIView does not fire when the application returns from the background. This is a problem, as my main application screen is showing values that are retrieved from the user settings, and if the user has changed these while the application was in the background I need to have the screen refreshed. I have read that one should register for the UIApplicationWillEnterForegroundNotification using NSNotificationCenter.
How do you do this in MonoTouch? Or does anyone know an alternate way of ensuring that the screen is always kept up to date, even when returning from the background?
You could try something along the lines of:
//Register for the notification somewhere in the app
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, EnteredForeground);
//snip
void EnteredForeground (NSNotification notification)
{
// do your stuff here
}
Bear in mind you would need to do this for every view controller you'd like to update when enterting from the background!
On a page I have some fields that I want to be "readonly" (in my meaning they can't be accessed but they will store values, read earlier question in this matter if issues...).
I use a client JS setting these attributes on page load:
$(".readonly").attr('readonly', true);
If I have a partial update on any of these fields the attribute is lost and the field is accessible.
What is the best practice to overcome this and make it work?
Every partial refresh has a oncomplete method bound to it. What you could do is add code to the oncomplete method so the item is being set readonly again. Another, better, approach would be not to change the attribute clientside but to have hidden fields which are used to store the data.
When you have an event bound to for instance an Link control you can change the oncomplete code by clicking in your source pane on the event tag. When you browse the events section in the properties pane you will see the onComplete, onError, onStart properties. You can add your own clientside script in these properties.
Before trying to overcome the "problem" You shoud try to understand what exactly partial refresh do and where the state of application is kept.
Unfortunately partial refresh is replacing current html content (or rather part of it) with a newly created one and only form fields that has backing controls will keep state.
I suggest You should try setting readonly property on controls which You would like to make readonly (if there is some logic here You can always use ssjs).
Optionally You can try to preserve the state on the client side by using csjs global variables but this is rather hard to manage.
And one more thing - try to use the technology to solve the problem(xpages) and try not to hack Your way through with use of stuff that You accidentally know (jquery).
I would agree with jjtbsomhorst on using onComplete event. But another alternative could be setting the readonly property via code like this:
var textField:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText1");
var readOnlyAttr:com.ibm.xsp.complex.Attr = new com.ibm.xsp.complex.Attr("readonly", "readonly");
var list:java.util.ArrayList = new java.util.ArrayList();
list.add(readOnlyAttr);
textField.setAttrs(list);
You could call this on the afterPageLoad event of the XPage. But I really don't know whether this would be the best way to about!
I have a simple view containing a richtextbox and a button. I want to enter text into my RTB and on clicking my button have viewmodel print the RTB.
I have my command set up from the views print button and in my viewmodel have a UIElement property.
My question is how do I bind the RTB directly to my UIElement property in viewModel?
I'm fine with hooking individual properties of the RTB up but what about the whole control?
Not certain how you might accomplish that using databinding, how about just setting the reference manually?
MyControl.Loaded += (s, e) => {
((ViewModel)MyControl.DataContext).UiElementProperty = MyControl;
};
... although I'm not sure why you want to perform a task like that in the VM. How about just handling it in the view? Otherwise you might also encounter "dialogue must be user initiated" type errors.