2013-03-19 4 views
0

이미 URL에서로드 된 이미지가 포함 된 목록보기가 있습니다. 로드 중일 때 각 이미지 에 회전 원과 같은 것을 추가하고 싶습니다. 지금은로드되기 전에로드되는 이미지를 대체하기 위해 기본값을 사용했습니다. 여기서 주로 발견하는 것은 모든 클래스가 AsyncTask를 확장한다는 것입니다. 글쎄, 내가 가진 것은 다음과 같다 :이미지가로드되는 동안 서클 애니메이션로드 추가

나는 json을 파싱하는 활동이있다.

//constructor 
    public MyCustomAdapter (Context c, List<RowItem> items){ 
    this.context = c; 
    this.sRowItems = items; 
    imageLoader=new ImageLoader(c.getApplicationContext()); 
} 
. 
. 
. 

public View getView(int position, View convertView, ViewGroup parent){ 
    ViewHolder holder = null; 

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 

    if(convertView == null){ 
     convertView = inflater.inflate(R.layout.list_layout, null); 
     holder = new ViewHolder(); 
     holder.txtName = (TextView) convertView.findViewById(R.id.name); 
     holder.txtDesc = (TextView) convertView.findViewById(R.id.desc); 
     holder.imageView = (ImageView) convertView.findViewById(R.id.prof_pic); 



     convertView.setTag(holder); 
    }else{ 
     holder = (ViewHolder) convertView.getTag(); 
    } 

    RowItem sItem = (RowItem) getItem(position); 

    holder.txtName.setText(sItem.getShopName()); 
    holder.txtDesc.setText(sItem.getShopDesc()); 
    imageLoader.DisplayImage(sItem.getImageUrl(), holder.imageView); 

    return convertView; 
} 

그럼 난 내 이미지 로더 클래스가 : 그럼 내가 BaseAdapter를 확장하는 MyCustomAdapter 있습니다. 그래서 AsyncTask 대신, 나는 일반적인 자바 쓰레드를 사용했다.

public class ImageLoader { 

    MemoryCache memoryCache=new MemoryCache(); 
    FileCache fileCache; 
    private Map<ImageView, String> imageViews=Collections.synchronizedMap(new WeakHashMap<ImageView, String>()); 
    ExecutorService executorService; 

public ImageLoader(Context context){ 
    fileCache=new FileCache(context); 
    executorService=Executors.newFixedThreadPool(5); 
} 

final int stub_id=R.drawable.ic_launcher; 

public void DisplayImage(String url, ImageView imageView) 
{ 
    imageViews.put(imageView, url); 
    Bitmap bitmap=memoryCache.get(url); 
    if(bitmap!=null) 
     imageView.setImageBitmap(bitmap); 
    else 
    { 
     queuePhoto(url, imageView); 
     imageView.setImageResource(stub_id); 
    } 
} 

private void queuePhoto(String url, ImageView imageView) 
{ 
    PhotoToLoad p=new PhotoToLoad(url, imageView); 
    executorService.submit(new PhotosLoader(p)); 
} 

내가

ProgressDialog mDialog = new ProgressDialog(getApplicationContext()); 

를 사용하는 유래 여기에 답변을 보았다하지만 난 내하여 ImageLoader 클래스에 배치 할 때 내 코드와 함께 작동하지 않았다 : 그것의 부분이있다. 이 로딩 애니메이션 원을 구현하는 데 어려움을 겪고 있습니다. 도움주세요. 매우 감사합니다. 사전 실행에

답변

4

각 목록 항목에서 진행 막대 되세요. 이미지를 다운로드 할 때마다이 진행 표시 줄을 숨 깁니다 [가시성 설정 해제]. 귀하의 XML은 또한 내가 다운로드가 실패 할 경우, 귀하의 경우이 텍스트보기를 제거하고 기본 이미지를 표시 및 다운로드가 실패 할 경우 진행 막대를 숨길 수 있습니다 표시하는 텍스트보기가

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/imgToBeSet" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:contentDescription="@string/img_cont_desc_common" /> 

    <ProgressBar 
     android:id="@+id/imgProgress" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/textMsg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/imgToBeSet" 
     android:layout_centerHorizontal="true" 
     android:visibility="gone" 
     android:text="@string/msg_download_failed" /> 

</RelativeLayout> 

뭔가

을 보일 것입니다.

+0

좋아요, 제가 이걸 쏠 게요 .. – elL

0

: doInBackground에서

ProgressDialog pd= new ProgressDialog(getApplicationContext()); 
pd.setMessage("Please wait while Image lis being loaded"); 
pd.show(); 

() : postExecute에

pd.setMessage("Downloading image ...."); 

:

pd.setMessage(""); 
pd.dismiss(); 
+0

하지만 AsyncTask를 사용하지 않는 메신저 ... – elL

+0

사용 레이아웃 파레트에서이 같이 당신의 XML로 진행 막대 : XML : ProgressBar p = (ProgressBar) findViewById (R.id.pb); p.setEnabled (true); –

관련 문제