0

The entry field from the view is being populated on the content page. And in the view it is set as IsEnabled=false;. Whenever it is set as disabled the value of the entry is not getting set.

Please take a look at the code below:

    public class DetailsView : ContentView
    {
        public static Entry txtdetailsName;
        public DetailsView()
        { 
            Label lbldetailsName = new Label { Text = Resource.detailsName, FontAttributes = FontAttributes.Bold, Style = (Style)Application.Current.Resources["LabelStyle"] };
            txtdetailsName = new Entry { Style = (Style)Application.Current.Resources["entryStyle"], IsEnabled = false  };


            StackLayout stDetailsName = new StackLayout
            {
                Padding = new Thickness(10, 0, 10, 0),
                Children ={ 
                    lbldetailsName,
                    txtdetailsName
                }
            };
            Content = new StackLayout
            {
                Padding = new Thickness(0, 0, 0, 20),
                Children = {stDetailsName}
            };
        }
    }

In content page:

public TestDetailsPage()
{
    getDetailsData();
}

private async void getDetailsData()
{
    Test test = new Test();
    test = await getTestDetails();
    loadView(test);
}

public async Task<Test> getTestDetails() 
{
    //...
    return Test;
}

public void loadView(Test test)
{
    DetailsView = new DetailsView();
    //DetailsView.txtdetailsName.Text = Test.Name;
    DetailsView.txtdetailsName.Text = "Some Text";
}  

But it doesn't seem to set the value. Not sure what is causing the issue.

Edit

I tested the app on three android devices Micromax Canvas (Android version 6.0.1), Asus Zenfone(Android version 4.4.2) and Samsung Galaxy Tab 2 (Android version 4.1.2). On Asus zenfone and Samasung galaxy tab 2, the value for the disabled field is displayed as expected while on Micromax canvas the disabled text-boxes are empty.

Android version could be the issue?

Arti
  • 2,993
  • 11
  • 68
  • 121

1 Answers1

0

Looks like loadView is possibly not creating DetailsView on the main thread. Can you check to make sure it is? The async void might be swallowing that Exception.

joe
  • 1,125
  • 9
  • 18
  • It does create DetailsView. I tested the app on 3 devices(Micromax Canvas (Android version 6.0.1), Asus Zenfone(Android version 4.4.2) and Samsung Galaxy Tab 2 (Android version 4.1.2)) and strangely it worked on two devices(Asus zenfone and Samasung galaxy tab 2). The android version could be the issue? – Arti Apr 28 '16 at 04:58
  • It certainly could be the Android version. Is your app using the FormsAppCompatActivity? – joe Apr 28 '16 at 13:12
  • No, MainActivity.cs is inheriting from FormsApplicationActivity – Arti Apr 29 '16 at 04:27
  • Would you please tell me which field I will have to set to make my pages full screen? – Arti Apr 29 '16 at 12:46
  • Could you try to inherit from FormsAppCompatActivity to see if that works? Full screen should be [here](http://stackoverflow.com/questions/2868047/fullscreen-activity-in-android). – joe Apr 29 '16 at 18:03