私は、ユーザーが設定アクティビティで多くのアニメーションから選択できるようにしようとしている画像スライドショーアプリを持っているので、それを達成するためにSharedPreferencesを使用しました。アンドロイド開発、そして私は私のコードに何かが欠けていると思います、
修正するための助けをお願いします。感謝します。
MainActivity.java
public class MainActivity extends Activity {
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
private int[] IMAGE_IDS = {
R.drawable.one, R.drawable.two, R.drawable.three,R.drawable.four,R.drawable.five,
R.drawable.six,R.drawable.seven, R.drawable.eight, R.drawable.nine,
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 1000; // delay for 1 sec.
int period = 8000; // repeat every 4 sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
public void onClick(View v) {
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
private void AnimateandSlideShow() {
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
boolean animation_two = getPrefs.getBoolean("animation_two", true);
boolean animation = getPrefs.getBoolean("animation", false);
boolean animation_one = getPrefs.getBoolean("animation_one", false);
if (animation_two == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView3_Left);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
slidingimage.startAnimation(rotateimage);
finish();
}else if(animation_one == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView3_Left);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_in);
slidingimage.startAnimation(rotateimage);
finish();
}else if (animation == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView3_Left);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
slidingimage.startAnimation(rotateimage);
finish();
} else if(animation_two == false && animation == false && animation_one == false){
slidingimage = (ImageView)findViewById(R.id.ImageView3_Left);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
slidingimage.startAnimation(rotateimage);
finish();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.action_settings:
Intent p = new Intent("com.test.demo.SETTING");
startActivity(p);
break;
}
return false;
}
}