在读《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的特性么? 该怎么理解?
本文分享了一位初学者阅读《Android.Apps.for.Absolute.Beginners》的心得体会,对比中文教材,该书不仅详细介绍了每一步操作流程,还深入浅出地讲解了相关概念。文章特别提到了书中关于final变量用法的例子,帮助读者更好地理解其作用。
497

被折叠的 条评论
为什么被折叠?



