2012/3/1 Android导入包错误

package taos.android;

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class TestActivity extends Activity {
    /** Called when the activity is first created. */
	int[] images = new int[]{
			R.drawable.a,
			R.drawable.b,
			R.drawable.c,
			R.drawable.d,
			R.drawable.e
	};
	int currentImage = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LinearLayout main = (LinearLayout)findViewById(R.id.root);
        final ImageView image = new ImageView(this);
        main.addView(image);
        image.setImageResource(images[0]);
        image.setOnClickListener(new OnClickListener(){
        	public void onClick(View v){
        		if(currentImage >= 4)
        			currentImage = -1;
        		image.setImageResource(images[++currentImage]);
        	}
        });
    }
}

image.setOnClickListener(new OnClickListener(){ 这一行出现错误:

The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments (new DialogInterface.OnClickListener(){})

解决办法:导入了错误的包,将import android.content.DialogInterface.OnClickListener;

改为:import android.view.View.OnClickListener;即可。

 
 

你可能感兴趣的:(Android)