Java onResume和onCreate
我的应用程序在模拟器上加载,但不执行我要求它执行的操作。我已经将代码放在onResume方法中,它应该循环3次,中间有15秒的中断。它不能这样做。有什么方法可以做到这一点吗 为了详细说明,我需要一个方法来打开应用程序,显示一些文本视图和颜色,等待15秒,显示更多的文本视图和颜色,等待15秒,并显示文本视图和颜色 这是我的密码: JAVAJava onResume和onCreate,java,android,onresume,Java,Android,Onresume,我的应用程序在模拟器上加载,但不执行我要求它执行的操作。我已经将代码放在onResume方法中,它应该循环3次,中间有15秒的中断。它不能这样做。有什么方法可以做到这一点吗 为了详细说明,我需要一个方法来打开应用程序,显示一些文本视图和颜色,等待15秒,显示更多的文本视图和颜色,等待15秒,并显示文本视图和颜色 这是我的密码: JAVA 您不能在15秒内阻止onResume方法。 它在主线程上运行 例如,您可以使用AsyncTask来更新ui,也可以使用方法ViewTreeObserver.On
您不能在15秒内阻止
onResume
方法。
它在主线程上运行
例如,您可以使用AsyncTask
来更新ui,也可以使用方法ViewTreeObserver.OnGlobalLayoutListener
或处理程序
例如:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Update UI
}
}, 15000);
你可以找到更多信息
例2:
ViewTreeObserver vto=mActionCustomView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
@Override public void onGlobalLayout(){
mActionCustomView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
//....
runnable.run();
}
}
更多信息。您需要在15秒后运行的处理程序中编写代码
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Update UI here
}
}, 15000);
我不太懂你的代码。我是否将代码放入处理程序中?处理程序是放在onResume方法内部还是外部?我可以把处理程序放在onResume方法中吗?我不太明白把处理程序放在哪里。我应该用哪种方法?我必须为此创建单独的线程吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.anish.mapactivity.LotA"
android:orientation="horizontal"
android:id = "@+id/toplayout"
android:weightSum="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/layout1"
android:orientation="vertical">
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot1"
android:layout_marginTop="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot2"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot3"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot4"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot5"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/layout2"
android:orientation="vertical">
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot6"
android:layout_marginTop="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot7"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot8"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot9"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot10"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/layout3"
android:orientation="vertical">
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot11"
android:layout_marginTop="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot12"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot13"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot14"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
<TextView
android:layout_width="90dp"
android:layout_height="90dp"
android:id = "@+id/spot15"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#ffffff"/>
</LinearLayout>
</LinearLayout>
03-08 04:16:20.657 2655-2655/com.example.ani.opener D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-08 04:16:20.707 2655-2655/com.example.ani.opener I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
03-08 04:16:20.707 2655-2655/com.example.ani.opener W/dalvikvm﹕ VFY: unable to resolve virtual method 386: Landroid/content/res/TypedArray;.getType (I)I
03-08 04:16:20.707 2655-2655/com.example.ani.opener D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
03-08 04:17:06.088 2655-2655/com.example.ani.opener D/﹕ HostConnection::get() New Host Connection established 0xb7dced40, tid 2655
03-08 04:17:06.348 2655-2655/com.example.ani.opener W/EGL_emulation﹕ eglSurfaceAttrib not implemented
03-08 04:17:06.368 2655-2655/com.example.ani.opener D/OpenGLRenderer﹕ Enabling debug mode 0
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Update UI
}
}, 15000);
ViewTreeObserver vto=mActionCustomView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener(){
@Override public void onGlobalLayout(){
mActionCustomView.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
//....
runnable.run();
}
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Update UI here
}
}, 15000);