0
인터넷에서 이미지를로드하는 이미지 뷰가 있습니다. 웹에서 이미지를로드하고 비동기 작업을 사용하여 비트 맵 이미지로 변환합니다. 내 이미지 뷰에 정적 이미지를 표시하고 이미지가로드되는 동안 이미지 뷰 위에 진행률 회 전자를 표시하고 싶습니다. 문제는 내 xml 내에서 진행 스피너가 있고 내 비동기 작업 내에서 사용할 수 없습니다 및 진행률 회 전자도 imageview 내에서 볼 수 있도록하는 방법을 모르겠다. 어떻게해야합니까? 내 비동기 작업 클래스는 다음과 같습니다.이미지 뷰 내에서 스피너 애니메이션 표시
public class LoadImage extends AsyncTask<Void, Void, Bitmap>{
Context callingContext = null;
ImageView view;
String b = null;
ListView lv;
ProgressDialog p;
public LoadImage(Context c, ImageView view, String b){
this.view = view;
this.b = b;
this.callingContext = c;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
// p = (ProgressDialog) findViewById(R.id.progressBar1);
p = ProgressDialog.show(callingContext, "Loading Events", "Retrieving data from server, please wait...", true);
}
public Bitmap getBit(String data){
Bitmap bitmap;
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
//from web
try {
bitmap=null;
InputStream is=new URL(data).openStream();
BitmapFactory.decodeStream(is, null, bmOptions);
is.close();
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = 20;
is = new URL(data).openStream();
bitmap = BitmapFactory.decodeStream(is, null, o2);
is.close();
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
}
@Override
protected Bitmap doInBackground(String... arg0) {
// TODO Auto-generated method stub
Bitmap b = null;
URL imageUrl = null;
b = getBit(this.b);
return b;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if(result == null)
view.setImageResource(R.drawable.ic_launcher);
p.dismiss();
}
}
나는 이것을 내 코드에 통합하는 방법을 능숙하게 이해하지 못합니다. 내 비동기 작업 클래스 코드를 추가했습니다. 이것을 비동기 태스크 클래스에 어떻게 통합합니까? 그리고 내 프로그램의 어디에서나 속성 세트를 사용하지는 않습니다. – AndroidDev93
'ImageView' 대신'LoaderImageView'를 사용하십시오. 'AttributeSet'을 사용하고 싶지 않다면, 사용하지 마십시오. 컨텍스트를 취하는 다른 생성자를 추가하십시오. [Compound Controls] [1] [1] : http : //developer.android.com/guide/topics/ui/custom-components.html#compound http://developer.android.com/guide/topics/ui을 참조하십시오. /custom-components.html#compound –