Mvvmcross Android TextInputEditText Binding Enabled - xamarin.android

I have a Switch and a TextInputEditText. Both 'Enabled' are bound to the same field in the viewmodel.
When the activity is loaded, the bound field is set to false. The Switch is disabled as expected. However, the TextInputEditText is enabled. The 'Clickable' has the same issue. Text is bound successfully.
After changed the bound field to true and then false, the TextInputEditText Enable & Clickable work correctly. It seems that it only happens when it is loaded initially.
<android.support.v7.widget.SwitchCompat
style="#style/EntryTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxLang="Text LabelDeferArrivalNotice"
local:MvxBind="Checked RouteMarker.DeferArrivalNotice; Enabled RouteMarker.ArrivalNotice" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/edittext_route_marker_EffectiveFromDateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="false"
android:focusableInTouchMode="false"
style="#style/EntryTextStyle"
local:MvxLang="Hint LabelEffectiveFromTime"
local:MvxBind="Text DateTimeToString(RouteMarker.EffectiveFromDateTime);
Enabled RouteMarker.ArrivalNotice;
Clickable RouteMarker.ArrivalNotice;
Click PromptDeferTimeCommand" />
Is there anything special I have to do with the TextInputEditText?
Thanks

This is an issue with MvvmCross, as Stuart said, there are some interaction between ICommand.CanExecute and the Enabled property. Switching the binding to :
local:MvxBind="Click PromptDeferTimeCommand;Enabled RouteMarker.ArrivalNotice;Clickable RouteMarker.ArrivalNotice;"
Hope to help somebody who searched this problem.

Related

#region in axml file for xamarin.android

hello I am trying to make my code in the axml file more readable I have a lot of switches in my program and I want to shrink this part of the code. I read something about it and I found
<!--#region Name-->
My Code
<!--#endregion-->
But it is referred as a normal comment. Could you help me out? I am using Visual Studio 2017 in case it is important to mention.
# region in axml file for xamarin.android
If you want to make the .axml file more readable, you could click the indent button: Effect.
Or you could use the <include/> tag embed another layout inside the current layout to make it more readable. For example, create a titlebar.axml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/titlebar_bg"
tools:showIn="#layout/activity_main" >
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gafricalogo" />
</FrameLayout>
Use it in another layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/app_bg"
android:gravity="center_horizontal">
<include layout="#layout/titlebar"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
android:padding="10dp" />
...
</LinearLayout>
Update:
I think the XAML Regions is what you are looking in your .axml file.
Update 2:
Install this plugin for your Visual Studio, close all your Visual Studio windows and reopen the VS. Then, you could the the #Region function for your
<!-- Region (Any Text You Want) -->
Your Code
<!-- EndRegion -->

Floating hint textbox does not show up correctly

I have a textbox with the following AXML code:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gebruikers naam"
local:MvxBind="Text UserName"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
The problem is that if the text box is filled on startup(which happens when someone has logged into the app before) the text box shows up like this:
But it has to show up like this:
What am I doing wrong?

MVVMCross w/ Bugsense causes weird issues with binding EditText on Android

I ran into a very weird situation when I installed the BugSense package on my MVVMCross app. Every time I type a letter into the EditText the cursor moves to the first character. This is highly annoying as I have to arrow over to the end of the field to type the next character!
What I did was on the override of the "OnCreate" of my SplashScreenView I set up this:
protected override void OnCreate(Bundle bundle)
{
BugSenseHandler.Instance.InitAndStartSession(new ExceptionManager(), ApplicationContext, "xxxxxxxx");
base.OnCreate(bundle);
}
When my splash screen goes away it moves to my LoginViewModel. My axml for my Login View looks like so:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/white_full_box">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="false"
android:layout_centerInParent="true"
android:layout_marginBottom="#dimen/table_margin"
android:layout_marginLeft="#dimen/table_margin"
android:layout_marginTop="#dimen/dialog_margin"
android:padding="#dimen/zero"
android:background="#drawable/white_full_box">
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:ems="10"
android:hint="username"
android:layout_marginLeft="#dimen/table_margin"
android:inputType="textVisiblePassword"
android:singleLine="true"
local:MvxBind="Text UserName">
<requestFocus />
</EditText>
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:hint="password"
android:layout_marginLeft="#dimen/table_margin"
android:inputType="textPassword"
local:MvxBind="Text Password" />
<Button
android:id="#+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:layout_marginRight="#dimen/dialog_margin"
android:text="Login"
style="#style/ButtonStyle"
local:MvxBind="Click LoginCommand" />
</RelativeLayout>
</RelativeLayout>
And I just have normal properties that bind to the Username, Password and Login button in the view model. I did a couple things to verify this behavior:
1.) I left the bugsense initialization code and removed the Text bind from the username. In this scenario the username would behave properly but the password field would always move the character to the first character after each text entry.
2.) I reimplemented the text bind to the username field and then commented out the BugSense initialization code and everything appeared to work correctly again.
What is happening here? Where should I be doing the BugSense initialization in an MVVMCross app?
My solution was to switch to Raygun.io because that does not appear to have the same issue.
Bugsense does appear to be looking into the issue which you can follow along HERE

LinearLayout just ignores MvxBind (MvvmCross)

I'm trying to bind LinearLayout to show/hide in accordance with ViewModel State.
For some reason it works great for buttons and textviews but not for LinearLayout.
What could be the reason?
<LinearLayout
android:orientation="vertical"
android:minWidth="25dp"
android:minHeight="25dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="Visibility WaitingForConfirmation">
I just tried a quick test using the bool Visible pseudo-property and it worked for both TextView and for LinearLayout
<TextView
android:text="Random text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Visible Generosity > 12" />
<LinearLayout
android:orientation="vertical"
android:minWidth="25dp"
android:minHeight="25dp"
android:background="#ff0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="Visible Generosity > 12" />
The Visibility property binds to the same underlying Android hide/display mechanism - it just uses the Visibility plugin to convert bool->Visibility enum - so the code should work for that too...
Update: I also tried within the Droid sample https://github.com/slodge/MvvmCross-Tutorials/tree/master/ValueConversion
Within this I just changed the displayed view to LinearLayout in https://github.com/slodge/MvvmCross-Tutorials/blob/master/ValueConversion/ValueConversion.UI.Droid/Resources/Layout/View_Visibility.axml
This sample worked fine:
What is WaitingForConfirmation? I suspect it's a bool, in which case you will need to use a visibility converter, just as you do in Windows binding. A standard visibility converter is provided in the Visibility plugin, and can be used:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#ff0000"
local:MvxBind="Visibility MakeItVisible, Converter=Visibility" />
One final note: MvvmCross does continue to adapt (and hopefully improve) its binding type conversion - so at some point you may be able to get away with using bools with Visibility enums - but this probably isn't ever going to be recommended practice - normally it's better to use value converters to take control of your binding operations (just like in Windows).

How to use multiline textview with scrollbars in monodevelop/monoandroid

I am new in monodevelop/monoandroid.I need code for showing multiline text in textview I have tried bellow but still its not working.I think there should be some code that I have to include in .cs file,but I am not getting what to use there.
I have used c# code also but its not working. I think ellipsize is a android attribute thats why its not working.Please give me some solution.
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="10dip"
android:orientation="vertical"
android:layout_gravity="center" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="10dip">
<TextView
android:id="#+id/tv_policy1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="Terms of Service O-job Information Terms of Service O-job Information Terms of Service O-job Information Terms of Service O-job Information for Personal non-commercialaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa use only sdfjkj asdfjklfj sdfjkljdf sdfjkljflkj sdfskjfkl sdfjklsdjf sdfkljsdklfj sdfjhsdkfh"
android:textColor="#000000"
android:maxLines="3"
android:singleLine="false"
android:textSize="14dip" />
</RelativeLayout>
</ScrollView>
Please advice....
Thanks in advance!
Try this format:
<ScrollView>
<RelativeLayout>
<TextView/>
<TextView/>
<RelativeLayout/>
<ScrollView/>
Then you can use the align methods given in a RelativeLayout.
Edit:
Explain what your problem is! Do you get an error when compiling or is the text not shown properly? Be more specific.
Also, why do you use attributes like : android:maxLines="3" or android:singleLine="false" or android:layout_height="60dip" in your TextView. Translated this means: The text must have more than one line but a maximum of 3. Also it can't be longer than 60dip.
Depending on the Text that are very strict rules. Use these rules android:layout_width="match_parent" android:layout_height="wrap_content" to make sure that the text can be displayed correctly, remove the attributes I mentioned before in your TextView.

Resources