在我的应用程序中,操作栏上有一个图标,当我点击某些东西开始同步时,所以我想将图标更改为gif,当同步它再次更改时
我尝试了这个,但应用程序崩溃了:
MenuItem menuItem = (MenuItem)findViewById(R.id.update_data); ((Menu) menuItem).getItem(0).setIcon(getResources().getDrawable(R.drawable.space));
这是我的代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.update_data:
Log.i("TAG", "on update data");
if(Globals.onFitnessTutorial){
Globals.onFitnessTutorial = false;
finish();
CommonUtils.startIntent(this, ProgressActivity.class);
}
if (MyApplication.isBluetoothConnection) {
timerSync();
forLoadingProgress();
MyApplication.showLoadingProgress();
String str1 = getSharedPreferences("DateTime", Context.MODE_PRIVATE).getString("user_time", "");
String str2 = "2013-07-14";
SQLiteDatabase sql2 = new SaveDataBase.SaveDateBaseHelp(this).getWritableDatabase();
Cursor select = sql2.rawQuery("SELECT * from db_pedometer_info ORDER BY pedometer_year, pedometer_month, pedometer_day DESC LIMIT 1; ", null);
if(select != null && select.getCount() == 1){
select.moveToFirst();
String year = select.getString(select.getColumnIndex("pedometer_year"));
String month = select.getString(select.getColumnIndex("pedometer_month"));
String day = select.getString(select.getColumnIndex("pedometer_day"));
str2 = year + "-" + month + "-" +day ;
}
我想在这里更改图标:
if(MyApplication.isBluetoothConnection)
更新
这样app崩溃了:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.update_data:
MenuItem img = (MenuItem)findViewById(R.id.update_data);
((View) img).setBackgroundResource(R.drawable.sync);
AnimationDrawable frameAnimation = (AnimationDrawable) ((View) img).getBackground();
frameAnimation.start();