의도가 하나의 활동을 통해 전달되고 인터넷의 일부 데이터가 제 2의 활동에서 다운로드 될 때 안드로이드 프로젝트에서 진행률 표시 줄을 구현해야하므로 눈에 띄는 부분이 있습니다 사용자가 항목을 클릭 할 때와 활동이 표시 될 때 사이의 지연.Android : 진행 대화 상자
나는 이것을 위해 몇 가지 다른 접근 방식을 시도했지만 아무 것도 원하는대로 작동하지 않습니다. 다음 코드를 사용하고 있습니다. 그리고 진행 대화 상자는 무한 루프 안에 있습니다.
public class BackgroundAsyncTask extends AsyncTask<String, Integer, Bitmap> {
int myProgress;
@Override
protected void onPostExecute(Bitmap result) {
iv.setVisibility(View.VISIBLE);
iv.setImageBitmap(result);
dialog.cancel();
dialog.dismiss();
}
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(ProfileNormalUserPhotos.this, "Loading...", "Please wait...");
}
@Override
protected Bitmap doInBackground(String...paths) {
return DownloadFile(imageUrl);
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
progressBar.setProgress(values[0]);
}
}
public Bitmap DownloadFile(String url){
URL myFileUrl;
Bitmap bitmap=null;
try {
myFileUrl = new URL(imageUrl);
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
bitmap = BitmapFactory.decodeStream((InputStream) new URL(
imageUrl).getContent());
bitmap = Bitmap.createScaledBitmap(bitmap,70 , 70, true);
System.out.println("name of bitmap"+bitmap.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
}
return bitmap;
}
그리고 다음은
public class ImageAdapter extends BaseAdapter {
Context mContext;
private String[] stringOnTextView;
public ImageAdapter(Context c) {
mContext = c;
}
// BitmapManager.INSTANCE. setPlaceholder(BitmapFactory.decodeResource(
// context.getResources(), R.drawable.icon));
public ImageAdapter(Context Context,
String[] stringOnTextView) {
this.mContext=Context;
this.stringOnTextView=stringOnTextView;
}
public int getCount() {
return stringOnTextView.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("**************"+position);
View v = null;
if(convertView==null){
try{
{
System.gc();
// dialog = ProgressDialog.show(ProfileNormalUserPhotos.this, "Loading...", "Please wait...");
imageUrl = "http://ondamove.it/English/images/users/";
imageUrl=imageUrl+stringOnTextView[position];
System.out.println(imageUrl);
LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.icon, null);
TextView tv = (TextView)v.findViewById(R.id.text);
tv.setText("Profile Image "+(position+1));
/* URL myFileUrl = new URL(imageUrl);
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
imageUrl).getContent());
bitmap = Bitmap.createScaledBitmap(bitmap, 80, 80, true);*/
// new ImageView(mContext);
iv= (ImageView)v.findViewById(R.id.image);
new BackgroundAsyncTask().execute(imageUrl);
//iv.setImageBitmap(bitmap);
//dialog.cancel();
// System.out.println(bitmap.getHeight());
System.out.println("++++++++"+R.id.image);
}
}catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
}
else
{
try{
v = convertView;}
catch(Exception e){
System.out.println(e);
}
}
return v;
}
}
는 사람이 이상 도와 줄 수
내 어댑터 클래스입니까?
나는 그것도 시도했지만 작동하지 않습니다. – Aditya1510
작동하지 않는 부분은 무엇입니까? AsyncTask? 또는 구현에 문제가 있습니까? – user370305