Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TextView即使在调试时也不更新_Android_Android Activity_Xamarin.ios_Xamarin_Textview - Fatal编程技术网

Android TextView即使在调试时也不更新

Android TextView即使在调试时也不更新,android,android-activity,xamarin.ios,xamarin,textview,Android,Android Activity,Xamarin.ios,Xamarin,Textview,我有一个包含非常基本布局代码的活动: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_pa

我有一个包含非常基本布局代码的活动:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <TextView
        android:id = "@+id/WebServiceClassInformation"
        android:text = "Making connection with servers"
        android:layout_centerInParent = "true"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content">
    </TextView>

</RelativeLayout>
现在,有一件有趣的事情。在调试过程中,当控件处于“保持连接”线路上,并将其传递到睡眠线路时,TextView不会显示在我的手机屏幕上,更新的文本也不会显示,但它会睡眠1秒钟,并导航到登录活动

在那里,当我按下back键时,我可以看到文本视图及其更新值。这是一个手机截图

这就是问题所在。我希望用户看到文本1秒钟,但它会导航到下一个活动。有什么建议吗??我在这里遗漏了什么?

使用postDelayed(Runnable r,long delayMillis)启动您的活动和服务

Runnable r = new Runnable() {
        @Override
        public void run() {
            StartService (new Intent(this, typeof(MyService)));
            StartActivity (new Intent(this, typeof(Login)));
        }
    };
new Handler().postDelayed(r, 1000);

当你使用Thread.sleep(1000)时,正常情况下1秒内什么都没有发生…

你应该覆盖OnResume并将代码放在那里。使resum异步函数,然后使用wait。这将允许UI自我更新。我没有测试下面的样本,但这应该做的工作

    protected async override void OnResume()
    {
        base.OnResume();

        if (InternetConnectionCheck._InternetIsAvailable (this))
        {
            webServiceClassInfo = FindViewById<TextView> (Resource.Id.WebServiceClassInformation);
            webServiceClassInfo.Text = "Stay Connected to Internet";
            await Task.Delay(1000);
        }

        StartService (new Intent(this, typeof(MyService)));

        StartActivity (new Intent(this, typeof(Login)));
    }
protected async override void OnResume()
{
base.OnResume();
如果(Internet连接检查。\u Internet可用(此))
{
webServiceClassInfo=findviewbyd(Resource.Id.webServiceClassInfo);
webServiceClassInfo.Text=“保持与互联网的连接”;
等待任务。延迟(1000);
}
StartService(新意图(this,typeof(MyService));
StartActivity(新意图(此,类型(登录));
}

您使用Java语言吗?它看起来不像Java?不,这不是Java。是的,我发现了mono,很有趣!非常感谢。你是说我应该将StartService和StartActivity代码移动到一个线程中??是的,我知道睡眠除了停止执行之外什么都不做:皮,这有什么奇怪的?不,不,我只是想确定你是不是在说:马上测试它!
    protected async override void OnResume()
    {
        base.OnResume();

        if (InternetConnectionCheck._InternetIsAvailable (this))
        {
            webServiceClassInfo = FindViewById<TextView> (Resource.Id.WebServiceClassInformation);
            webServiceClassInfo.Text = "Stay Connected to Internet";
            await Task.Delay(1000);
        }

        StartService (new Intent(this, typeof(MyService)));

        StartActivity (new Intent(this, typeof(Login)));
    }