Running on iPad.
I'm presenting a view controller modally. It is using MonoTouch.Dialog to show some text input fields, buttons, etc.
When tapping a textfield, the keyboard pops up. When tapping outside the textfield I would like to dismiss the keyboard but it won't go away. I read that dismissing the keyboard is not possible when presenting as FormSheet? Is that correct?
Here's my code. The selector gets called, but the keyboard stays where it is. As the textfields are created dynamicalls I cannot/don't want to call ResignFirstResponder() on each of them but instead let the view become first responder and then resign.
public override void ViewDidLoad ()
{
base.ViewDidLoad ( );
UITapGestureRecognizer oTapRecognizer = new UITapGestureRecognizer ( );
oTapRecognizer.AddTarget(this, new MonoTouch.ObjCRuntime.Selector("ViewTappedSelector:"));
this.View.AddGestureRecognizer ( o );
}
[Export( "ViewTappedSelector:" )]
public void ViewTapped ( UIGestureRecognizer sender )
{
this.View.BecomeFirstResponder ( );
this.View.ResignFirstResponder ( );
}
I read that dismissing the keyboard is not possible when presenting as FormSheet?
This is correct. If you'd like to dismiss the keyboard while showing a modal view, you'll have present it using a different modalStyle and you could resize the view to take the same frame as a formsheet.
Related
I’m a beginner, I can’t pass this level, please help.
I have a lot of forms with TextField (cust_no, cust_name), each with a button on the right,
press the button
A dialog can be display custom record, after selecting the required customer,
Write the selected cust_no, cust_name back to the Text_Field of Form.
I hope to write dialog as a public class, so that many class Forms can use this function, and can also smoothly write cust_no and cust_name back to their respective Form TextField.
In addition to backfilling cust_no,cust_name TextField for some Forms, some also need to query the consumption amount and write back the specified cust_amt TextField.
My trouble is that form button.addClickListener open a dialog,
Dialog’s Button_OK.addClickListener cannot know how I want to write back Form TextField and some have special query mechanisms, how to customize
Without seeing exactly how your code is structured, I can only give a quite generic answer. What you need is typically that something associated with the button for opening the dialog can know what to do with the result from the dialog, and it can also configure the dialog's OK button to carry out that action.
public class HelloWorldView extends VerticalLayout {
public HelloWorldView() {
TextField customerNumberField = new TextField("Customer number");
TextField customerNameField = new TextField("Customer name");
Button nameDialogButton = new Button("Open dialog", dialogOpenClick -> {
showDialog(customer -> {
customerNumberField.setValue(customer.getNumber());
customerNameField.setValue(customer.getName());
});
});
add(customerNumberField, customerNameField, nameDialogButton);
}
private void showDialog(Consumer<Customer> selectionAction) {
Select<Customer> customerSelect = new Select<>(new Customer("1", "Customer 1"),
new Customer("2", "Customer 2"));
customerSelect.setTextRenderer(customer -> customer.getName());
Dialog dialog = new Dialog();
dialog.add(customerSelect);
dialog.add(new Button("Select customer", click -> {
Customer selectedCustomer = customerSelect.getValue();
if (selectedCustomer != null) {
selectionAction.accept(selectedCustomer);
}
dialog.close();
}));
dialog.open();
}
}
I have a WebView and I am loading the data from the backend.The data is very long paragraph and it is in Html format.It is working.I have to implement change font size settings to my application.When radio button named "small" clicks,text should appear in small font,when "large" clicks text should appear in large font.The content dispaly is done in ChapterDetailFragment.class.The dialg which shows the "change font option" is in Menu in actionbar and in drawer.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.font_change) {
dialog = new Dialog(HomeActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.font_change_dialog);
dialog.show();
dialog.setCanceledOnTouchOutside(true);
//here i have to write the code for clicks of radiobutton "small","large"
}
}
This is the line for loading paragraph to the array adapter
ParagraphAdapter.class
mViewHolder.mChapterContextTextView.loadData(getItem(position - 1).getContent(), "text/html; charset=UTF-8;", null);
I don't know how to implement this.Please anyone help me
in onClick of "large" radio button, save value LARGE for large.Similarly in onClick of small radio button(value SMALL for small )
public void onTextLarge(View view) {
if (fragment.getClass().getSimpleName().equalsIgnoreCase("HomeFragment")){
setSharedPreference("FONT","LARGE");
fragment = new HomeFragment();
dialog.dismiss();
}
In the adapter,
if (fontsize.equals("LARGE")) {
mViewHolder.settings = mViewHolder.mChapterContextTextView.getSettings();
mViewHolder.settings.setTextZoom(mViewHolder.settings.getTextZoom() + 30);
mViewHolder.mChapterContextTextView.loadData(getItem(position - 1).getContent(),
"text/html; charset=UTF-8;", null);
Similarly done for fontsize.equals("SMALL"). :)
I have extended org.controlsfx.dialog.Dialog and added some TextField to it, which is supposed to act when ENTER button is pressed (if TextField has focus). However when I press ENTER, my dialog takes over of steering, and act like on OK button was pressed.
Is there any method which I can override in order to change this behavior (to intercept Enter action)?
Thanks in advance
I have received some workaround to this problem at ControlsFX mailing list which is good for me. To disable Dialog closing after Enter button is pressed in TextField we must consume event in EventHandler attached to this TextField
textField.addEventFilter(new EventHandler() {
public void handle(KeyEvent evt) {
.......
evt.consume();
}
});
For me works this:
dialog.getDialogPane().addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.ENTER) {
event.consume();
}
});
I am currently using this code to hide the keyboard in a monotouch iOS application when something outside the input elements are tapped.
var tap = new UITapGestureRecognizer ();
tap.AddTarget (() =>{
dvc.View.EndEditing (true);
});
dvc.View.AddGestureRecognizer (tap);
However, I would like to hide the keyboard when the user taps the top Navbar as well. I have seen this in other apps. How would I go about doing that?
Easiest way is to override TouchesEnded in your UIViewController.
This will give you any touch event inside the entire controller.
Then do something like this if you need ignore touches in a certain view:
public override void TouchesEnded(NSSet touches, UIEvent evt)
{
base.TouchesEnded(touches, evt);
if (evt.TouchesForView(viewYouWantToIgnore) == null) {
//Dismiss your keyboard here
}
}
I am using mfc CDialog. I need to show the close and minimize/maximize button, but they should not close or maximize the dialog. I have overriden OnClose method and kept the dialog open even if close button is clicked. But I am unable to block maximize and minimize of the dialog as there doesn't seem to be a OnMaximize method. Is there an alternative way?
You need to handle the WM_SYSCOMMAND message, watching for wParam == SC_MAXIMIZE.
If you catch the SC_MINIMIZE, you can do what you want and not pass it on to Windows.
msdn
Found this snippet here.
const int WM_SYSCOMMAND= 0x0112;
const int SC_MAXIMIZE= 0xF030;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SYSCOMMAND)
{
if((int)m.WParam==SC_MAXIMIZE)
{
MessageBox.Show("Maximized!!");
return; // swallow the message
}
}
base.WndProc (ref m);
}
You can not show at all the minimise/maximise icons i your dialog. You can do that by going to Dialog properties (right vlick on your Dialog Contorol --> Properties), Select Styles pain and unselect 'Minimise Box', 'Maximise Box'.