2016-05-02 7 views
0

私は、ディスクに保存された一連のデータを表示するためのGridLayoutManagerを使ってRecycler Viewを作成しています。しかし、最初の要素を更新すると、写真アプリのアイコンが下にランダムに表示され、クリックすると写真アプリでその画像が開きます。ここで何が起きてるの? enter image description hereリサイクルビューに表示されている写真APPの奇妙なアイコン?

アイコンがすぐに表示されます。 は、ここに私のコードです:

アダプタ

public class AdapterForCardView extends RecyclerView.Adapter<AdapterForCardView.CardAdapterHolder> 
{ 
private Context context; 
private File[] image_files; 
private File[] strings_of_files; 
private String logging=getClass().getSimpleName(); 
public AdapterForCardView(Context context, File[] image_files, File[] strings_of_files) 
{ 
    this.context = context; 
    this.image_files = image_files; 
    this.strings_of_files = strings_of_files; 
} 

@Override 
public CardAdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) 
{ 
    View view= LayoutInflater.from(context).inflate(R.layout.card_view_recycler,parent,false); 
    return new CardAdapterHolder(view); 
} 

@Override 
public void onBindViewHolder(CardAdapterHolder holder, int position) 
{ 
    Glide.with(context).load(image_files[position]).into(holder.getImageView()); 
    if (position!=holder.Position()) 
    { 
     if (holder.Position()!=-1)holder.getLoadingText().cancel(true); 
     removeAllText(holder.getTableLayout()); 
     LoadingText loadingText = new LoadingText(context,holder.getTableLayout()); 
     holder.setLoadingText(loadingText, position); 
     loadingText.execute(strings_of_files[position]); 
    } 
} 

private void removeAllText(TableLayout tableLayout) 
{ 
    tableLayout.removeAllViews(); 
} 

public void setStrings_of_files(File[] strings_of_files) 
{ 
    this.strings_of_files = strings_of_files; 
} 

public void setImage_files(File[] image_files) 
{ 
    this.image_files = image_files; 
} 

@Override 
public int getItemCount() 
{ 
    return image_files==null?0:image_files.length; 
} 

class CardAdapterHolder extends RecyclerView.ViewHolder 
{ 
    private TableLayout tableLayout; 
    private ImageView imageView; 
    private LoadingText loadingText; 
    private int position; 
    public CardAdapterHolder(View itemView) 
    { 
     super(itemView); 
     imageView=(ImageView)itemView.findViewById(R.id.image_view_card_view); 
     tableLayout=(TableLayout)itemView.findViewById(R.id.tableLayout); 
     position=-1; 
    } 

    public ImageView getImageView() 
    { 
     return imageView; 
    } 

    public TableLayout getTableLayout() 
    { 
     return tableLayout; 
    } 

    public LoadingText getLoadingText() 
    { 
     return loadingText; 
    } 

    public void setLoadingText(LoadingText loadingText,int position) 
    { 
     this.loadingText = loadingText; 
     this.position=position; 
    } 

    public int Position() 
    { 
     return position; 
    } 
} 
} 

レイアウト:これは私が最初の項目を私のデータを更新し、通知方法についてのコードが変更されている

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp"> 

<android.support.v7.widget.CardView android:id="@+id/card_view" 
            android:layout_width="match_parent" 
            android:layout_height="250dp" 
            android:layout_gravity="center" 
            android:layout_marginEnd="3dp" 
            android:layout_marginLeft="3dp" 
            android:layout_marginRight="3dp" 
            android:layout_marginStart="3dp" 
            app:cardBackgroundColor="@color/white" 
            app:cardCornerRadius="4dp"> 
    <RelativeLayout android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
     <ImageView android:id="@+id/image_view_card_view" 
        android:layout_width="match_parent" 
        android:layout_height="170dp" 
        android:scaleType="centerCrop"/> 
     <TableLayout android:id="@+id/tableLayout" 
        android:layout_width="match_parent" 
        android:layout_height="80dp" 
        android:layout_below="@id/image_view_card_view"/> 
    </RelativeLayout> 

</android.support.v7.widget.CardView> 

public class AsyncTaskForInternalFiles extends AsyncTask<Void, Void, File[]> 
{ 
private Context context; 
private AdapterForCardView adapterForCardView; 
private File[] labels; 
private boolean ifSaved; 
private String logging=getClass().getSimpleName(); 
public AsyncTaskForInternalFiles(Context context, AdapterForCardView adapterForCardView,boolean ifSaved) 
{ 
    this.context = context; 
    this.adapterForCardView=adapterForCardView; 
    this.ifSaved=ifSaved; 
} 
@Override 
protected File[] doInBackground(Void... params) 
{ 
    File internal_save = context.getDir(context.getResources().getString(R.string.directory_images), Context.MODE_PRIVATE); 
    File[] files = internal_save.listFiles(); 
    labels=context.getDir(context.getResources().getString(R.string.directory_labels),Context.MODE_PRIVATE).listFiles(); 
    sortItOut(files,labels); 
    return files; 
} 

private void sortItOut(File[] files, File[] labels) 
{ 
    PairForSorting[] pairForSorting=new PairForSorting[files.length]; 
    PairForSorting[] labelsForSorting=new PairForSorting[files.length]; 
    for (int i=0;i<files.length;i++) 
    { 
     pairForSorting[i] =new PairForSorting(files[i]); 
     labelsForSorting[i]=new PairForSorting(labels[i]); 
     Log.d(logging,files[i].getAbsolutePath()+"=fileNames"); 
     Log.d(logging,labels[i].getAbsolutePath()+"=labelNames"); 
    } 
    Arrays.sort(pairForSorting); 
    Arrays.sort(labelsForSorting); 
    for (int i=0;i<files.length;i++) 
    { 
     files[i]=pairForSorting[i].fi; 
     labels[i]=labelsForSorting[i].fi; 
    } 
} 

@Override 
protected void onPostExecute(File[] files) 
{ 
    if (files != null) 
    { 
     adapterForCardView.setImage_files(files); 
     adapterForCardView.setStrings_of_files(labels); 
     if (ifSaved)adapterForCardView.notifyItemInserted(0); 
     else adapterForCardView.notifyDataSetChanged(); 
    } 
} 
} 

これ以上のコードが必要な場合は、お気軽にコメントしてください。

録音したい場合は、それも送信できます。

+0

PS:奇妙な写真には申し訳ありません。 –

+0

カスタムROMでこれをテストしていますか? –

+0

それは酸素で運ばれています。 –

答えて

0

ギャラリーに画像を追加するためにブロードキャストするときにMediaScannerが問題を作成していたようです。 Oxygen OSを使用していた場合、またはすべてのAndroid搭載端末に同じバグを作成していた場合、問題が解決しない場合はまだ分かりません。 別のアクティビティから移行してから、MediaActivityがMainActivityに追加されましたが、現在は再び表示されません。これがOxygen OSのみであった場合はアップデートされ、通常のアンドロイドでは問題が発生しています。

関連する問題