我正在尝试创建一个显示离线照片幻灯片的应用程序,左右按钮。
public class MainActivity extends AppCompatActivity {
int count;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
count = 1;
setPicture();
}
private void left(View v){
--count;
setPicture();
}
private void right(View v){
++count;
setPicture();
}
private void setPicture(){
ImageView displayPicture = (ImageView) findViewById(R.id.imageView);
switch(count){
case 1:
displayPicture.setImageResource(R.drawable.a);
break;
case 2:
displayPicture.setImageResource(R.drawable.b);
break;
case 3:
displayPicture.setImageResource(R.drawable.c);
break;
}}
}
该应用程序可以处理第一张图像,但正如我按下右键,应用程序崩溃。