Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build recyclerView sliding deletion

2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to build recyclerView sliding deletion", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to build recyclerView sliding deletion" bar!

Package com.example.demo; import androidx.annotation.NonNull;import androidx.appcompat.app.AppCompatActivity;import androidx.recyclerview.widget.ItemTouchHelper;import androidx.recyclerview.widget.LinearLayoutManager;import androidx.recyclerview.widget.RecyclerView; import android.graphics.Canvas;import android.os.Bundle;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.LinearLayout;import android.widget.TextView; import java.util.ArrayList;import java.util.List / * * @ author Huang xudong * @ date 2020-7-26 * / public class MainActivity extends AppCompatActivity {private RecyclerView recyclerView; private List list=new ArrayList (); class MyAdpter extends RecyclerView.Adapter {class ViewHolder extends RecyclerView.ViewHolder {private TextView textView; private LinearLayout linearLayout; public ViewHolder (@ NonNull View itemView) {super (itemView) LinearLayout=itemView.findViewById (R.id.ll_main); textView=itemView.findViewById (R.id.tv_main);} @ NonNull @ Override public ViewHolder onCreateViewHolder (@ NonNull ViewGroup parent, int viewType) {View inflate = LayoutInflater.from (getApplicationContext ()) .originate (R.layout.itemology demotion parent, false); return new ViewHolder (inflate) } @ Override public void onBindViewHolder (@ NonNull ViewHolder holder, int position) {} @ Override public int getItemCount () {return list.size ();}} class CallBack extends ItemTouchHelper.Callback {@ Override public int getMovementFlags (@ NonNull RecyclerView recyclerView, @ NonNull RecyclerView.ViewHolder viewHolder) {return makeMovementFlags (0Med ItemTouchHelper.left) } @ Override public boolean onMove (@ NonNull RecyclerView recyclerView, @ NonNull RecyclerView.ViewHolder viewHolder, @ NonNull RecyclerView.ViewHolder target) {return false } @ Override public void onSwiped (@ NonNull RecyclerView.ViewHolder viewHolder, int direction) {/ * call max distance start onSwiped call * /} @ Override public void onChildDraw (@ NonNull Canvas c, @ NonNull RecyclerView recyclerView, @ NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState Boolean isCurrentlyActive) {if (actionState==ItemTouchHelper.ACTION_STATE_SWIPE) {/ * get {@ link TextView#getWidth ()} * / ViewGroup viewGroup= (ViewGroup) viewHolder.itemView TextView textView = (TextView) viewGroup.getChildAt (1); ViewGroup.LayoutParams layoutParams = textView.getLayoutParams (); if (Math.abs (dX))

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report