2016-03-26 10 views
0

Birden çok görüntü grubunu görüntülemek için çalışıyorum.Ayrıca her grubun görüntülenmesi için liste görünümünü kullanıyorum. bir metin görünümü, onay kutusu ve ızgara görünümü olacak. Izgara görünümünde, ilgili grubun her bir resmini görüntülemek zorundayım.Izgara görünümünde yukarı ve aşağı kaydırma yaptıktan sonra görüntüleri nasıl yükleyeceğinizi/güncelleyeceğinizi (async görev)

public class GridviewLoader extends AsyncTask<String,Void,Bitmap> { 

    private final WeakReference<ImageView> imageViewReference; 
    Context imageloadercontext; 

    public GridviewLoader(Context c,ImageView imageView) { 
     imageViewReference = new WeakReference<ImageView>(imageView); 
     this.imageloadercontext = c; 
    } 

    @Override 
    protected Bitmap doInBackground(String... params) { 
//  CommonlyUsed.logmsg("%%%%%%------Filepath: "+params[0]); 
     Bitmap bmp = BitmapLoader.loadBitmap(params[0], 100, 100); 
     return bmp; 
    } 

// @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    @Override 
    protected void onPostExecute(Bitmap bitmap) { 
     super.onPostExecute(bitmap); 
     if (isCancelled()) { 
      bitmap = null; 
     } 

     if (imageViewReference != null) { 
      ImageView imageView = imageViewReference.get(); 
      if (imageView != null) { 
       if (bitmap != null) { 
        imageView.setImageBitmap(bitmap); 
       } else { 
        Drawable placeholder = imageView.getContext().getResources().getDrawable(R.drawable.rsz_empty_photo); 
        imageView.setImageDrawable(placeholder); 
       } 

      } 

     } 
    } 
} 

Sorunum görüntüleri başlangıçta gösterdiğinizi geçerli:

public class CustomListAdapter extends BaseAdapter implements CompoundButton.OnCheckedChangeListener { 

    private Context listapadptercontext; 
    private List<IndividualGroup> listData; 
    private LayoutInflater layoutInflater; 
    GridViewAdapter mAdapter; 
    GridLayoutManager layoutManager; 

    public CustomListAdapter(Context _c,List<IndividualGroup> _listdata){ 
     this.listapadptercontext = _c; 
     this.listData = _listdata; 
     this.layoutInflater = (LayoutInflater) listapadptercontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public int getCount() { 
     return listData.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return listData.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder holder=null; 
     if (convertView == null) { 
      convertView = layoutInflater.inflate(R.layout.group_heading, null); 
      holder = new ViewHolder(); 
      holder.textView = (TextView) convertView.findViewById(R.id.textView1); 
      holder.checkBox = (CheckBox) convertView.findViewById(R.id.grpcheckbox); 
      holder.myGridView = (MyGridView) convertView.findViewById(R.id.gridView); 
      convertView.setTag(holder); 
     } else { 
      holder = (ViewHolder) convertView.getTag(); 
     } 

     IndividualGroup individualGroup = listData.get(position); 
     holder.textView.setText("Set" + (position + 1)); 
     holder.checkBox.setOnCheckedChangeListener(this); 
     layoutManager = new GridLayoutManager(listapadptercontext, 4); 
     mAdapter = new GridViewAdapter(listapadptercontext,0,individualGroup.getIndividualgrpofdupes()); 
     holder.myGridView.setAdapter(mAdapter); 
     return convertView; 
    } 

    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
//  IndividualGroup individualGroup = listData.get() 
    } 

    static class ViewHolder { 
     TextView textView; 
     CheckBox checkBox; 
     MyGridView myGridView; 
    } 
} 

Benim Gridview adaptör:

public class GridViewAdapter extends ArrayAdapter 
{ 
    private Context context; 
    private int layoutResourceId; 
    private LayoutInflater inflater; 
    private List<String> data = new ArrayList<String>(); 

    public GridViewAdapter(Context context,int layoutResourceId, List<String> data) { 
     super(context,layoutResourceId,data); 
     this.layoutResourceId = layoutResourceId; 
     this.context = context; 
     this.data = data; 
     this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public int getCount() 
    { 
     return data.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return position; 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

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

     if (row == null) { 
      row = inflater.inflate(R.layout.group_duplicate_image, parent, false); 
      holder = new ViewHolder(row); 
      holder.image = (SquareImageView) row.findViewById(R.id.img_duplicate_image); 
      holder.checkBox = (CheckBox) row.findViewById(R.id.individualcheckbox); 
      row.setTag(holder); 
     } else { 
      holder = (ViewHolder) row.getTag(); 
     } 
     String item = data.get(position); 
     if (holder.image != null) { 
      new GridviewLoader(context,holder.image).execute(item); 
     } 
     return row; 
    } 

    class ViewHolder implements CompoundButton.OnCheckedChangeListener { 
     SquareImageView image; 
     CheckBox checkBox; 

     ViewHolder(View view){ 
//   super(view); 
      image = (SquareImageView) view.findViewById(R.id.img_duplicate_image); 
      checkBox = (CheckBox) view.findViewById(R.id.individualcheckbox); 
      checkBox.setOnCheckedChangeListener(this); 
     } 

     @Override 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
//   ImageItem imageItem = data.get(position); 
     } 
    } 
} 

My gridviewloader (zaman uyumsuz görev) İşte benim ListeGörünüm adaptör sınıftır. ama aşağı kaydırdıktan sonra kaybolur. Ve tekrar yüklenmek için çok zaman alır. İşte benim düzenlerim:

İç görünüm listesi. Tablo görünümünde İçinde

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


    <LinearLayout 
     style="@style/linearLayoutStyleNoBgColor" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/deepyellow"> 

     <TextView 
      android:id="@+id/textView1" 
      style="@style/textFieldStyleType1WithCheckbox" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center|right" 
      android:textColor="@color/white" 
      android:textSize="15dp" /> 

     <CheckBox 
      style="@style/checkboxStyleType1" 
      android:id="@+id/grpcheckbox" 
      android:layout_width="20dp" 
      android:layout_height="20dp" 
      android:layout_alignRight="@+id/img_duplicate_image" 
      android:layout_gravity="center|right" 
      android:button="@null" 
      android:background="@drawable/customcheckbox" /> 
    </LinearLayout> 

<!--  <android.support.v7.widget.RecyclerView 
      android:id="@+id/rv_duplicates" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical"/>--> 



    <com.xxx.xxx.customviews.MyGridView 
     android:id="@+id/gridView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="2dp" 
     android:clickable="true" 
     android:columnWidth="100dp" 
     android:drawSelectorOnTop="true" 
     android:focusable="true" 
     android:gravity="center" 
     android:numColumns="4" 
     android:stretchMode="columnWidth" 
     android:verticalSpacing="5dp" /> 



</LinearLayout> 

:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/imagelayout" 
    android:weightSum="1"> 

    <com.remodupes.remoactivities.customviews.SquareImageView 
     android:id="@+id/img_duplicate_image" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:contentDescription="@null" 
     android:padding="2dp" 
     android:scaleType="fitXY"/> 

    <CheckBox 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:id="@+id/individualcheckbox" 
     android:layout_alignRight="@+id/img_duplicate_image" 
     android:button="@null" 
     android:background="@drawable/customcheckbox" 
     android:layout_alignBottom="@+id/img_duplicate_image" /> 
</RelativeLayout> 

Peki ben bu sorunu çözebilir.

+0

görüntü indirme, yükleme, önbelleğe alma ve görüntüleme, bundan daha karmaşıktır. Glide veya Picasso (Ajay cevabı tarafından önerildiği gibi) sizin için zaten uygulayan bir kütüphaneyi kullanmanız yeterlidir. – Budius

cevap

1

sen picasso için görüntü yükleyici veya picasso

kullanabileceği bir listede ben sonra modülün içine Picasso'nun jar eklemek gibi kullanabilirsiniz blog for your problem öneririm ile resim yüklemek için bir yol yoktur

Picasso. 
    with(State.mainContext). 
    load(parseImageFile.getUrl()). 
    into(null); 
İlgili konular