在读《Android.Apps.for.Absolute.Beginners》,非常适合初学者。 虽然是英文的,可是看了快一本了感觉所需的单词量还不到四级的要求。 相比看中文的安卓开发初级,似乎作者都是急着挣稿费的,很多地方只会教你怎么做而讲不出原理。 可英文书不但详尽的的把每一个步骤都列出来或直接上截图,并且还经常点拨一下难懂的概念。就像下面所列举的一样(p142):
@Override
public boolean onOptionsItemSelected(MenuItem item) {
LinearLayout bkgr= (LinearLayout)findViewById(R.id.uilayout);
final ImageView image=(ImageView)findViewById(R.id.imageView1);
AlertDialog.Builder builder=new AlertDialog.Builder(this);
Here is the code to customize our dialog:
builder.setTitle("Pick an Image!")
.setMessage("Please Select Image One or Image Two:")
.setCancelable(false)
.setPositiveButton("IMAGE 1", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id) {
image.setImageResource(R.drawable.image1);
}
})
.setNegativeButton("IMAGE 2", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
image.setImageResource(R.drawable.image2);
}
});
We work with the image object, which we know can’t be reassigned a value because it is final. This is to deal with situations where the event listener is used after the onOptionsItemSelected() method has terminated. In this case, a non-final image variable would not be around to take a new assignment, whereas a final variable is frozen in memory for access at all times (of course, this may never happen, but Java was built this way just to be sure).
“a non-final image variable would not be around to take a new assignment”这句话是否可理解为:一个非final类型的image变量将不能被分配新值? 可是这不正是final的特性么? 该怎么理解?