建议修改的代码:
1 public class MainActivity extends AppCompatActivity { 2 Button button; 3 ImageView imageView; 4 ProgressDialog progressDialog; 5 String IMAGE_PATH="http://image.baidu.com/search/redirect?tn=redirect&word=j&juid=51AEAB&sign=cibzwikaba&url=http%3A%2F%2Flife.northnews.cn%2F2015%2F0515%2F1927051_20.shtml&objurl=http%3A%2F%2Fupload.northnews.cn%2F2015%2F0515%2F1431655212431.jpg";
意见:一行代码过于冗长,不便于别人看,可以在适当的地方进行分行。
修改如下:
1 public class MainActivity extends AppCompatActivity { 2 Button button; 3 ImageView imageView; 4 ProgressDialog progressDialog; 5 String IMAGE_PATH="http://image.baidu.com/search/redirect?tn=redirect&word=j&juid=51AEAB&sign=cibzwikaba&url
=http%3A%2F%2Flife.northnews.cn%2F2015%2F0515%2F1927051_20.shtml&objurl
=http%3A%2F%2Fupload.northnews.cn%2F2015%2F0515%2F1431655212431.jpg";
建议修改的代码:
1 button.setOnClickListener(new View.OnClickListener() { 2 @Override 3 public void onClick(View view) { 4 new MyAsyncTask().execute(IMAGE_PATH); } 5 }) 6 ; 7 }
意见:不符合编程规范,符合的位置随意乱放,而且每段代码没有相应的注释,看代码的人会费劲。
修改如下:
1 button.setOnClickListener(new View.OnClickListener() { 2 @Override 3 public void onClick(View view) { 4 new MyAsyncTask().execute(IMAGE_PATH); 5 } 6 }); 7 } //对按钮进行监听,执行我编写的任务,通过图片的路径调用图片
建议修改的代码:
1 public class way extends AsyncTask<String,Integer,byte[]>{ 2 @Override 3 protected void onPreExecute() { 4 super.onPreExecute(); 5 progressDialog.show(); 6 }
意见:方法名不明确,看代码人不能一目了然的看出来这是应用在哪里的方法
修改如下:
1 public class MyAsyncTask extends AsyncTask<String,Integer,byte[]>{ 2 @Override 3 protected void onPreExecute() { 4 super.onPreExecute(); 5 progressDialog.show(); 6 }