私の問題は、リストをスクロールしているときにアイテムが入れ替わることです。どうすれば彼らの位置を固定できますか?
私のレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1sp"
>
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/network_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:visibility="gone" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:visibility="gone"
android:padding="8dp" />
<TextView
android:id="@+id/subreddit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/network_image"
android:visibility="gone"
android:text="New Text" />
<TextView
android:id="@+id/article_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/card_view"
android:layout_alignStart="@+id/card_view"
android:layout_below="@+id/author"
android:visibility="gone"
android:text="New Text" />
</LinearLayout>
オブジェクトを動かし続けるのは画像だと思うので、テキストの可視性をなくしました。このアイテムの交換を修正できる方法はありますか?
アダプターコード:
public class MyRecyclerAdapter extends RecyclerView.Adapter<ListViewRowHolder> {
private List<ListItems> listItemsList;
private Context mContext;
private ImageLoader mImageLoader;
private int focusedItem = 0;
String[] urls = {"http://i.telegraph.co.uk/multimedia/archive/03020/ANIMALS_GOOSE_3020723k.jpg","http://www.evolo.us/wp-content/uploads/2014/01/New-York-Vertical-Central-Park-Jeffrey-Lee-Rui-Liu-Tina-Qiu-01.jpg"};
public MyRecyclerAdapter(Context context,List<ListItems> listItemsList,ImageLoader imageLoader){
this.listItemsList = listItemsList;
this.mContext = context;
this.mImageLoader = imageLoader;
}
@Override
public ListViewRowHolder onCreateViewHolder(final ViewGroup viewGroup, final int position){
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_row, null);
ListViewRowHolder holder = new ListViewRowHolder(v);
holder.relativeLayout.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
TextView redditUrl = (TextView) v.findViewById(R.id.url);
String postUrl = redditUrl.getText().toString();
Intent intent = new Intent(mContext, WebViewActivity.class);
intent.putExtra("url", postUrl);
mContext.startActivity(intent);
}
});
return holder;
}
@Override
public void onBindViewHolder(final ListViewRowHolder listViewRowHolder, int position) {
ListItems listItems = listItemsList.get(position);
listViewRowHolder.itemView.setSelected(focusedItem == position);
listViewRowHolder.getLayoutPosition();
Random rand = new Random();
int n = rand.nextInt(2);
Log.d("photos",listItems.getThumbnail()+" "+ listItems.getUrl());
listViewRowHolder.thumbnail.setImageUrl(urls[n], mImageLoader);
listViewRowHolder.thumbnail.setDefaultImageResId(R.drawable.image1);
listViewRowHolder.title.setText(Html.fromHtml(listItems.getTitle()));
listViewRowHolder.subreddit.setText(Html.fromHtml(listItems.getSubreddit()));
listViewRowHolder.author.setText(Html.fromHtml(listItems.getAuthor()));
listViewRowHolder.url.setText(Html.fromHtml(listItems.getUrl()));
}
public void clearAdapter(){
listItemsList.clear();
notifyDataSetChanged();
}
@Override
public int getItemCount(){
return (null != listItemsList ? listItemsList.size() : 0);
}
}