我有一个RecyclerView和一个活动ImageView.我正在使用它RecyclerView来水平显示图像列表.当我在点击图片RecyclerView将ImageView在活动中应显示图像的大局观.到目前为止一切正常.
现在活动还有两个ImageButtons:imageButton_left和imageButton_right.当我点击时imageButton_left,该图像ImageView应向左转,并且该缩略图RecyclerView应反映此更改.情况类似imageButton_right.
我能够旋转ImageView.但是,我怎么能旋转缩略图RecyclerView?我如何获得ViewHolder的ImageView?
码:
活动XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<ImageView
android:id="@+id/original_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:scaleType="fitXY"
android:src="@drawable/image_not_available_2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageButton
android:id="@+id/imageButton_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:background="@drawable/rotate_left_icon" />
<ImageButton
android:id="@+id/imageButton_right"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我正在加载一个类别列表,根据选择的类别,我需要显示相应类别的产品RecyclerView.因此,当我第一次启动时,Fragment我需要模拟用户点击默认类别 - 在这种情况下,它将是第一个.
我怎么能这样做?
我一直在为我的Android应用程序使用SwipeableRecyclerView来为我的recyclerView启用滑动.RecyclerView包含cardViews列表.
我试图为卡片实现撤消功能,当向左滑动时会被删除(第一次滑动显示撤消,下一次滑动触发器删除)
我正在尝试以下代码(部分工作,我猜)
SwipeableRecyclerViewTouchListener srvTouchListner = new SwipeableRecyclerViewTouchListener(rvTimerList,
new SwipeableRecyclerViewTouchListener.SwipeListener(){
@Override
public boolean canSwipe(int i) {
return true;
}
@Override
public void onDismissedBySwipeLeft(RecyclerView recyclerView, int[] ints) {
for(int position : ints){
View view = recyclerView.getChildAt(position);
if (view.getTag(R.string.card_undo) == null) {
if(viewStack == null) {
saveToViewStack(position, view);
final ViewGroup viewGroup = (ViewGroup) view.findViewById(R.id.time_card2);
view.setTag(R.string.card_undo, "true");
viewGroup.addView(view.inflate(TimerSummary.this, R.layout.timeslot_card_undo, null));
}
} else {
Log.d(TAG, "Removing Item");
deleteTimeSlot(timerInstanceList.get(position));
Toast.makeText(TimerSummary.this, "Deleted!", Toast.LENGTH_SHORT).show();
timerInstanceList.remove(position);
finalSummaryAdapter.notifyItemRemoved(position);
}
}
finalSummaryAdapter.notifyDataSetChanged();
}
@Override
public void onDismissedBySwipeRight(RecyclerView recyclerView, int[] …Run Code Online (Sandbox Code Playgroud) 其实我想RecyclerView在我的fragment.class. 为此,我尝试getter在我的adapter班级中设置 a然后尝试在 my 中访问它,fragment但我无法访问 views 。
适配器类代码:
private List<ViewHolder> holder_list=new ArrayList<>();
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder_list.add(holder);
}
public ViewHolder getViewHolder(int position){
return holder_list.get(position);
}
Run Code Online (Sandbox Code Playgroud)
片段代码:
MessageAdapter.ViewHolder holder= msgAdp.getViewHolder(msgAdp.getItemCount()-1);
//Here holder.mMessageView is a text view
Toast.makeText(ctx,holder.mMessageView.getText().toString(),Toast.LENGTH_SHORT).show();
Run Code Online (Sandbox Code Playgroud) 我有一个RecyclerView水平的LinerLayout。它显示从 10 到 1 的数字,用于对某事物进行评分。
当我选择 10 并滚动回 1 并选择 1 时。我必须更新 UI 以删除 10 上的选择并更新 1 上的选择。但是,当我用来删除 10 上的选择时,findViewHolderForAdapterPosition()它给了我一个NullPointerException
我正在使用 ViewHolder 获取位置getAdapterPosition()。
然后,我使用该位置通过调用我的回收器视图对象来获取 ViewHolder findViewHolderForAdapterPosition(),并更新 UI 以删除 10 中的选择。
vh = (RatingRecyclerAdapter.ViewHolder)
mRecycler.findViewHolderForAdapterPosition(previousPosition);
vh.textRating.setBackgroundResource(R.drawable.rating_background_selected_orange);;
Run Code Online (Sandbox Code Playgroud)
通过一些测试,我发现当我尝试在不滚动的情况下做同样的事情时,效果很好。但是,只有当我滚动时,它才会给我一个NullPointerException
我该如何解决?
根据此处的要求,我们提供了 Adapter 类中的一些重要代码。
@Override
public void onBindViewHolder(RatingRecyclerAdapter.ViewHolder holder, int position) {
String itemText = itemList.get(position);
holder.textRating.setText(itemText);
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView textRating;
public ViewHolder(View itemView) {
super(itemView);
textRating = …Run Code Online (Sandbox Code Playgroud) android nullpointerexception android-adapter android-recyclerview