I have Xamarin form application. In App.xaml.cs I have event handler for button. If I set different background color on click it works. If I have also navigation like Application.Current.MainPage.Navigation.PushAsync(new Page1()) color doesn't change. How navigation break background color change?
private void Navigate(object sender, EventArgs e)
{
Button? button = sender as Button;
if (button != null)
{
Application.Current.MainPage.Navigation.PushAsync((Page)Activator.CreateInstance(new Page1());
button.BackgroundColor = Color.FromHex("#332196F3");
}
}
Related
I have single view layout with edit text and image. To display data in listview i am using arrayadapter . While entering value in Edit text in first row. The data gets repeated to another row in listview . How can i resolve this ?
View rowView = null;
try {
if (convertView == null) {
//inflating view.
rowView =
inflater.inflate(R.layout.list_single_view,null,false);
}
else
{
//Setting view if layout is already implemented.
rowView = convertView;
}
imageView = (ImageView)
rowView.findViewById(R.id.iv_activity_image_single);
//Facing issue here in editText . The entered text gets repeated
et_image_name = (EditText)
rowView.findViewById(R.id.txt_user_notes);
et_image_description = (EditText)
rowView.findViewById(R.id.txt_user_description);
//Loading image using universal image loader to imageView
if (equipmentPicturesList.get(position) != null) {
Constant.imageLoader.displayImage("file:///" +
equipmentPicturesList.get(position).toString(), imageView, Constant.options,
new SimpleImageLoadingListener());
}
else {
imageView.setBackgroundResource(R.drawable.ic_launcher);
}
}
catch (Exception e) {
Logger.loadStackTrace(e);
}
return rowView;
The EditText messes with the focus of whatever layout it is in. That can be a little tricky by itself, but in a ListView it causes all sorts of problems. But there is a way around that, it will work if you put the EditText inside the footer or header of the ListView with addHeaderView or addFooterView. The reason that it works in the header or footer is that the header and footer views are not recycled by the ListView. Alternatively you can call setHasTransientState() on the EditText to prevent it from being recycled even as a normal view inside the ListView.
But beware that turning off the view recycling - especially if you do it for multiple views - can impact performance and scrolling speed of the ListView.
I have a webview containing some text. I need to be able to swipe on the webview and make text selection at the same time. The problem is after I have implemented the swipe overriding the onTouchEvent method, the other features of the webview seem to have freezed, links in the webview aren't clickable anymore, and the text selection (after longClick) doesn't work anymore, I need to make to implement the swipe and preserve the other features of the webview.
I tried to override the longClick click method as well and use the following method to implement text selection:
public void selectAndCopyText() {
try {
Method m = WebView.class.getMethod("emulateShiftHeld", null);
m.invoke(MyWebView.this, null);
}
catch (Exception e1) {
e1.printStackTrace();
KeyEvent shiftPressEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
shiftPressEvent.dispatch(this);
}
}
but it didn't work for when this method is called I only get the upper bar for copy/ paste/ search/ websearch... but no actual selection on the webview occur.
I need to add done button on tool bar with UIkeyboard(type) Number Pad, to resign the keyboard while click on done button. I used Input Accessory View but it adds to normal keyboard also ,i need to add this where i have number pad.For example i have a text field it takes only numbers there i need this.Other than places i don't want to show input Accessory view.Or else i need to show tool bar with Done button for Iphone using Mono Touch.
Thank you.
public override UIView InputAccessoryView
{
get
{
if (dismiss == null)
{
UIToolbar toolbar = new UIToolbar(new RectangleF(0, 0, 320, 30));
toolbar.BarStyle = UIBarStyle.BlackTranslucent;
dismiss = new UIView(new RectangleF(-20, -120, 320, 30));
dismissBtn = new UIButton(new RectangleF(268, 1, 50, 29));
dismissBtn.SetBackgroundImage(new UIImage("Images/done_active.png"), UIControlState.Normal);
dismissBtn.AllEvents += delegate
{
HideKeyBoard();
};
toolbar.AddSubview(dismissBtn);
dismiss.AddSubview(toolbar);
dismiss.BringSubviewToFront(dismissBtn);
dismiss.BringSubviewToFront(toolbar);
}
return dismiss;
}
}
I have an Activity that populates two views on a ViewFlipper. I added an onTouch(View v, MotionEvent event) public boolean method to the Activity. The method is implemented so that when the person taps on the screen the ViewFlipper goes to the next view. It works great but some of the text is too long so I went into my XML file and surrounded the textfield in one of my ViewFlipper views with a linearlayout and then a ScrollView. But now when I'm viewing the fields that are too long and show a scroll bar, I can't display the previous view. The onTouch method in my main activity isn't being executed. I have not been able to figure this out. I've read some posts about implementing or overriding the methods in ScrollView but I don't know where to do this in my activity. Does anyone know how I can program ScrollView to not intercept but keep its ability to scroll the view?
ScrollView myScroll;
myScroll.setOnTouchListener(new OnTouchListener){
#Override
public boolean onTouch(View v, MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (oldTouchValue < currentX) {
//left swipe
return true;
}
if (oldTouchValue > currentX) {
//right swipe
return true;
}
return false;
}
}
I'm a newbie. I can't figure out how and where to call ResignFirstResponder to get rid of the keyboard when the user finished entering the text in an UITextField. I'm a bit confused by the UIResponder class. Mono documentation says: "To dismiss the keyboard, send the UIResponder.ResignFirstResponder message to the text field that is currently the first responder." How to do so? Can someone post a simple working example? There are many examples in Obj-C but none in C#. Many thanks.
Here's an example I've done recently:
private UITextField _textField;
public override void ViewDidLoad()
{
_textField = new UITextField();
_textField.Text = "King Alfonso III";
_textField.Bounds = bounds;
_textField.Placeholder = "Username";
_textField.ShouldReturn = delegate
{
_textField.ResignFirstResponder();
return true;
};
View.AddSubview(_textField);
}
Also if you are submitted a form with a button, make sure you resign all the textfields in the button click, to avoid getting responder errors.
public void ButtonClick(object sender, EventArgs e)
{
_textField.ResignFirstResponder();
// All other textboxes
// Other button logic
}