亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

跟著視頻打代碼,結果出現xx已經停止,求大神指導怎么修改。

這是我的mainactivity

package com.example.handler_012;


import android.app.Activity;

import android.os.Bundle;

import android.os.Handler;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.ImageView;

import android.widget.TextView;



public class MainActivity extends Activity {

private TextView tv;

private Handler handler1=new Handler();

private ImageView imv;

private MyRunnable myRunnable=new MyRunnable();

private int images[]={R.drawable.image_1,R.drawable.image_2,R.drawable.image_3};

private int i;

class MyRunnable implements Runnable{

public void run(){

i++;

i=i%3;

imv.setImageResource(images[i]);

handler1.postDelayed(myRunnable, 1000);

}

}


@Override

? ? protected void onCreate(Bundle savedInstanceState) {

? ? ? ? super.onCreate(savedInstanceState);

? ? ? ? setContentView(R.layout.activity_main);

? ? ? ? tv=(TextView) findViewById(R.id.textview);

? ? ? ? imv=(ImageView) findViewById(R.id.imageView1);

? ? ? ?// handler1=new Handler();

? ? ? ? handler1.postDelayed(myRunnable, 1000);

// ? ? ? ?new Thread(){

// ? ? ? ? public void run() {

// ? ? ? ? try {

// Thread.sleep(1000);

// handler1.post(new Runnable() {

//

// @Override

// public void run() {

// // TODO Auto-generated method stub

// tv.setText("update thread");

// }

// });

//

// } catch (InterruptedException e) {

// // TODO Auto-generated catch block

// e.printStackTrace();

// }

// ? ? ? ?

// ? ? ? ? };

// ? ? ? ?}.start();

? ? }



}



這是activity.xml文檔:

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"

? ? android:paddingLeft="@dimen/activity_horizontal_margin"

? ? android:paddingRight="@dimen/activity_horizontal_margin"

? ? android:paddingTop="@dimen/activity_vertical_margin"

? ? tools:context="com.example.handler_012.MainActivity" >


? ? <TextView

? ? ? ? android:id="@+id/textview"

? ? ? ? android:layout_width="wrap_content"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:text="@string/hello_world" />


? ? <ImageView

? ? ? ? android:id="@+id/imageView1"

? ? ? ? android:layout_width="wrap_content"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:layout_below="@+id/textview"

? ? ? ? android:layout_centerHorizontal="true"

? ? ? ? android:layout_marginTop="132dp"

? ? ? ? android:src="@drawable/ic_launcher" />


</RelativeLayout>



正在回答

2 回答

格式化一下吧。

0 回復 有任何疑惑可以回復我~

private int i;

class MyRunnable implements Runnable{

public void run(){

i++;

i=i%3;

imv.setImageResource(images[i]);

handler1.postDelayed(myRunnable, 1000);

}

}

這里面的 i 沒有初始化啊,應該是int i = 0;

2 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android面試??虷andler詳解
  • 參與學習       54869    人
  • 解答問題       192    個

學Android開發,必學Handler,也是Android面試???/p> 進入課程

跟著視頻打代碼,結果出現xx已經停止,求大神指導怎么修改。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號