主Activity:
public class MainActivity extends Activity {
PicActivity Draw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Draw = new FaceActivity(this);
setContentView(Draw); //新建surfaceview
}
......//省略菜单创建
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case MENU_EYES:
FaceActivity.LoadPic();
break;
}
return super.onOptionItemSelected(item)
}
}
==================================
PicActivity
public class FaceActivity extends SurfaceView implements SurfaceHolder.Callback {
public FaceActivity(Context context) {
super(context);
this.getHolder().addCallback(this);
paintPic = new Paint();
paintPic.setAntiAlias(true);
this.LoadPic();
}
protected static void LoadPic() {
paintPic = new Paint();
imagecl = BitmapFactory.decodeResource(getResources(), R.drawable.cl);
imagecr = BitmapFactory.decodeResource(getResources(), R.drawable.cr);
}
......
}
我想通过第一个Activity里面的菜单,调用第二个java里面的LoadPic函数,利用switch方法(还没写代码)加载不同的图片.
但是eclipse提示我,LoadPic要是static才能被第一个Activity调用,而改成静态之后,getResources()方法就不能使用,也就读不出图片了.
求解,应该怎么办!~
HUH函数
汪汪一只猫