我做了一个非常简单的壁纸应用程序,之前使用过相同的代码。我没有错误,但由于某种原因我的图像不可点击,我错过了一些可能有人帮助...这是迄今为止的代码
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class Nflwallpapers extends Activity implements View.OnClickListener{
ImageView display;
int toPhone;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
toPhone = R.drawable.azcard1;
display = (ImageView)findViewById(R.id.IVdisplay);
ImageView image1 = (ImageView) findViewById(R.id.IVimage1);
ImageView image2 = (ImageView) findViewById(R.id.IVimage2);
ImageView image3 = (ImageView) findViewById(R.id.IVimage3);
ImageView image4 = (ImageView) findViewById(R.id.IVimage4);
ImageView image5 = (ImageView) findViewById(R.id.IVimage5);
ImageView image6 = (ImageView) findViewById(R.id.IVimage6);
Button setWall = (Button)findViewById(R.id.setwallpaper);
image1.setOnClickListener(this);
image2.setOnClickListener(this);
image3.setOnClickListener(this);
image4.setOnClickListener(this);
image5.setOnClickListener(this);
image6.setOnClickListener(this);
setWall.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.IVimage1:
display.setImageResource(R.drawable.azcard1);
toPhone =R.drawable.azcard1;
break;
case R.id.IVimage2:
display.setImageResource(R.drawable.azcard2);
toPhone =R.drawable.azcard2;
break;
case R.id.IVimage3:
display.setImageResource(R.drawable.azcard3);
toPhone =R.drawable.azcard3;
break;
case R.id.IVimage4:
display.setImageResource(R.drawable.azcard4);
toPhone =R.drawable.azcard4;
break;
case R.id.IVimage5:
display.setImageResource(R.drawable.azcard5);
toPhone =R.drawable.azcard5;
break;
case R.id.IVimage6:
display.setImageResource(R.drawable.azcard6);
toPhone =R.drawable.azcard6;
break;
case R.id.setwallpaper:
InputStream yes = getResources().openRawResource(toPhone);
Bitmap whatever = BitmapFactory.decodeStream(yes);
try{
getApplicationContext().setWallpaper(whatever);
}catch(IOException e){
e.printStackTrace();
}
break;
}
}
};
答案 0 :(得分:0)
一切似乎都适合你的班级。检查你的xml布局设置... horizontalScrollView和LinearLayout ..