我想在我的项目上添加点击监听器,RecyclerView这样当我点击某个项目时,它会启动一个新项目Intent并从 Web 服务器检索有关该项目的数据。我尝试了很多建议,但没有一个有帮助。
我的 RecylerView 类
public class GetPrice extends AppCompatActivity {
private RecyclerView recyclerView;
private GridLayoutManager gridLayoutManager;
private CustomAdapter adapter;
private List<MyData> dataList;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getpricerecycle);
recyclerView =(RecyclerView) findViewById(R.id.recycler_view);
dataList = new ArrayList<>();
load_data_from_server(0);
gridLayoutManager = new GridLayoutManager(this,1);
recyclerView.setLayoutManager(gridLayoutManager);
adapter = new CustomAdapter(this,dataList);
recyclerView.setAdapter(adapter);
}
private void load_data_from_server(final int id) {
AsyncTask<Integer,Void,Void> task = new AsyncTask<Integer, Void, Void>() {
@Override
protected Void doInBackground(Integer... params) {
OkHttpClient client = new …Run Code Online (Sandbox Code Playgroud) 这是我的代码
@Override
public void onBindViewHolder(final RecyclerViewHolder holder, int position) {
final Songs songs = arrayList.get(position);
holder.favorite.setChecked(songs.getFavorite()); // this line makes me confusing.
holder.favorite.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
int r = db.update_favorite(b,songs.getTitle(),songs.getArtist());
compoundButton.setChecked(b);
}
});
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是我是否包含此代码
holder.favorite.setChecked(songs.getFavorite());
到onBindViewHolder,当我更改切换按钮的状态并向下滚动然后向上滚动时,切换按钮的状态将自身更改为原始状态。澄清一下,当切换按钮状态从 false 变为 true 并且用户向下和向上滚动时,切换按钮会自动变为原始状态,即为 false。
即使用户向下滚动,如何使切换按钮保持状态变化?请帮我。
我正在使用 recyclerview 来显示来自 Web 服务的数据。根据特定条件,我需要删除特定的回收者视图项。所以我正在使用 View.Gone。但它显示空白。我在谷歌上搜索了这个问题并将高度设置为 wrapcontent,但它不起作用。请任何人帮助我。
我的代码:xml:项目
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/businfo"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
app:contentPaddingBottom="10dp"
app:contentPaddingTop="16dp"
android:elevation="10dp"
android:layout_margin="5dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="@+id/travel_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="14sp"
android:layout_marginLeft="5dp"
android:textColor="@color/holo_blue_light"
android:text="CGR Travels"/>
<TextView
android:id="@+id/bus_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:textSize="14sp"
android:textColor="#F04C3B"
android:layout_marginRight="30dp"
android:text="Rs.349"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="5dp"
android:background="#b6b6b6"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/arrtime_desttime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:textSize="15sp"
android:textColor="#1e356a"
android:text="9.00P.M - 7.00AM"/> …Run Code Online (Sandbox Code Playgroud) 我有一个适配器类,我可以从中加载所有视频Firebase。
但问题是我无法同时加载图像和视频RecyclerView
看看我做了什么:
toro如果您想播放视频,我正在使用库自动ExoPlayer播放视频
这是我的适配器类
public class MainFeedAdapter extends RecyclerView.Adapter<TestAdapter.MyViewHolder> {
private static final String TAG = "MainfeedAdapter";
private List<Photo> moviesList;
private DatabaseReference mReference;
private Context mContext;
private String currentUsername = "";
private int mLayoutResource;
private LayoutInflater mInflater;
private Photo photo;
private MyViewHolder mHolder;
public class MyViewHolder extends RecyclerView.ViewHolder implements ToroPlayer{
static final int LAYOUT_RES = R.layout.main_list;
private ExoPlayerViewHelper helper;
private CircleImageView profile_image;
//private String likeString;
private TextView username,time,caption,likes,comment,stars;
private SquareImageView image;
private LikeButton …Run Code Online (Sandbox Code Playgroud) 我想创建一个回收视图。包含如此多产品的购物车,每当您长按产品列表项时,回收视图将显示一个上下文菜单,然后选择删除以将其从产品列表中删除。但是在获取要删除的产品的位置时遇到了一些问题。这是我的回收视图支架代码
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener,View.OnCreateContextMenuListener {
TextView quantity;
TextView name;
TextView price;
ImageView pic;
ImageButton increase;
ImageButton decrease;
int quantityInt=1;
LongClickListener longClickListener;
public int getQuantityInt() {
return quantityInt;
}
void changeQuantityDisplay(int number)
{
quantity.setText(Integer.toString(number));
}
public void setQuantityIntPlus(int quantityInt) {
this.quantityInt = quantityInt+1;
}
public void setQuantityIntMinus(int quantityInt) {
this.quantityInt = quantityInt-1;
}
public MyViewHolder(View itemView) {
super(itemView);
View view=LayoutInflater.from(context).inflate(R.layout.activity_cart,null,false);
name=(TextView)itemView.findViewById(R.id.listproduct_name);
price=(TextView)itemView.findViewById(R.id.listproduct_price);
pic=(ImageView)itemView.findViewById(R.id.listproduct_img);
increase=(ImageButton)itemView.findViewById(R.id.increasebtn);
decrease=(ImageButton)itemView.findViewById(R.id.decreasebtn);
quantity=(TextView) itemView.findViewById(R.id.listproduct_quantity);
itemView.setOnLongClickListener(this);
itemView.setOnCreateContextMenuListener(this);
}
public void setLongClickListener(LongClickListener lc)
{
this.longClickListener=lc;
} …Run Code Online (Sandbox Code Playgroud) 我目前正在创建一个自定义对话框来显示从 00:00 到 23:59 的时间,我使用 kotlin 作为开发语言。我的问题是,当我打开对话框时,回收站视图出现错误。这是我的代码
日历对话框类
class CalendarDialog : DialogFragment() {
/**
* Define variables
*/
private val mDaysList : MutableList<Days> = ArrayList()
private val dayMonthYear = "2018-06-14" //TODO fetch the date of today
/**
* Initialize the adapter
*/
private val adapter = CalendarAdapter(mDaysList)
/**
* Initialize the layout manager
*/
private fun getLinearLayoutManager(): LinearLayoutManager {
return LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false)
}
private fun initView() {
setDataListItems()
recyclerViewCalendar?.adapter = adapter
recyclerViewCalendar?.layoutManager = getLinearLayoutManager()
recyclerViewCalendar?.setHasFixedSize(true)
}
override fun onCreateView(inflater: …Run Code Online (Sandbox Code Playgroud) android android-lifecycle android-fragments kotlin android-recyclerview
这是我的布局 xml:
<RelativeLayout 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:background="@color/fragment_body"
android:fitsSystemWindows="true">
<include
android:id="@+id/contextToolBar"
layout="@layout/context_toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/contextToolBar"
android:scrollbarSize="5dp"
android:scrollbarThumbVertical="@color/scrollbarColor"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<ProgressBar
android:id="@+id/delete_progress"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
Run Code Online (Sandbox Code Playgroud)
它在回收视图中显示图像网格。我可以选择一堆图像并可以选择删除它们。以下是删除逻辑:
public void deleteSelectedFiles(final Context context, final List<MediaModel> selectionList) {
String confirmationMessage = getString(R.string.delete_confirm_message);
new AlertDialog.Builder(context)
.setTitle(getString(R.string.action_delete))
.setMessage(confirmationMessage)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
View progressBar = getActivity().findViewById(R.id.delete_progress);
dialog.cancel();
progressBar.setVisibility(View.VISIBLE);
deleteFileList(selectionList, this.getActivity());
progressBar.setVisibility(View.GONE);
})
.setNegativeButton(android.R.string.no, null).show();
}
Run Code Online (Sandbox Code Playgroud)
我希望在删除操作进行时进度条显示在前台。但它只是不显示。任何帮助将不胜感激。
android android-layout android-progressbar progress-bar android-recyclerview
在我的应用程序要使用recyclerView作秀特殊的数据,为此我想使用recyclerview与水平与展会滚动下一个和以前的数据。
例如横幅和下图:在此处输入链接描述
我LayoutManager该如何使用?
对于这一点,我知道我应该使用水平在LinearLayout。但我不知道如何显示下一个和上一个数据
请不要给我负分,请帮助我。
我的 RecyclerView 使用 ItemTouchHelper 启用向右滑动功能,如下所示
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(createHelperCallback());
itemTouchHelper.attachToRecyclerView(myRecyclerView);
private ItemTouchHelper.Callback createHelperCallback() {
return new ItemDragSwipeCallback(this, R.color.swipe_delete, R.drawable.ic_delete_black_24dp,
0, ItemTouchHelper.RIGHT, new ItemDragSwipeCallback.OnTouchListener() {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
// delete code
}
});
}
Run Code Online (Sandbox Code Playgroud)
自定义 ItemTouchHelper.SimpleCallback
public class ItemDragSwipeCallback extends ItemTouchHelper.SimpleCallback {
private Drawable mIcon;
private final ColorDrawable mBackground;
public interface OnTouchListener {
boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target);
void onSwiped(RecyclerView.ViewHolder …Run Code Online (Sandbox Code Playgroud) I am trying to run my app using Adapters and I am getting this error while doing that:
Mentioning that there are 3 adapters: ReviewsAdapter, StandupWithKey and VideoAdapter.
05-07 20:16:57.707 5326-5326/com.example.sefi.authenticationproject E/ReviewsAdapter: onBindViewHolder() >> 0 05-07 20:16:57.708 5326-5326/com.example.sefi.authenticationproject E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.sefi.authenticationproject, PID: 5326 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.sefi.authenticationproject.adapter.ReviewsAdapter.onBindViewHolder(ReviewsAdapter.java:48) at com.example.sefi.authenticationproject.adapter.ReviewsAdapter.onBindViewHolder(ReviewsAdapter.java:18) at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6482) at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6515) at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5458) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5724) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5563) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5559) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229) at …
java android android-studio recycler-adapter android-recyclerview