【问题标题】:how can i remove a particular item from recyclerview list如何从 recyclerview 列表中删除特定项目
【发布时间】:2017-08-14 14:59:11
【问题描述】:

我正在使用改造从服务器解析 json 数组。 我希望用户在 recyclerview 中自定义 JSON 输入 就像他们点击几秒钟一样,将为该特定 json 对象弹出一个删除选项!在 recyclerview 中,然后通过意图将其传递给另一个活动,这里我的意图活动是不完整的。 在此先感谢

    public class MainActivity extends AppCompatActivity {

        private static final String TAG = MainActivity.class.getSimpleName();
        private View Vm;
         @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.places_recycler_view);
            recyclerView.setLayoutManager(new LinearLayoutManager(this));

            ApiInterface apiService =
                    ApiClient.getClient().create(ApiInterface.class);
            Call<PlaceResponse> call = apiService.getdd();
            call.enqueue(new Callback<PlaceResponse>() {
                @Override
                public void onResponse(Call<PlaceResponse> call, Response<PlaceResponse> response) {
                    int statusCode = response.code();
                    List<place> places = response.body().getPlaces();
                    recyclerView.setAdapter(new PlaceAdapter(places, R.layout.list_item, getApplicationContext()));
                }

                @Override
                public void onFailure(Call<PlaceResponse> call, Throwable t) {
                    Log.e(TAG, t.toString());
                }
            });
    }
    protected void  OnNextButton(View vm){
            Intent intent = new Intent(this, csblow.class);
    intent.putExtra("places",List<place>toString());

     startActivity(intent);
    }
////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Place_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="72dp"
    android:orientation="horizontal"
    android:padding="16dp">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/city"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:paddingRight="16dp"
            android:textStyle="bold"

            android:textSize="16sp" />


        <TextView
            android:id="@+id/lat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="16dp"
            />

        <TextView
            android:id="@+id/lng"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:paddingRight="16dp"
            />
        <TextView
            android:id="@+id/needle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:paddingRight="16dp"
            />
    </LinearLayout>


</LinearLayout>

【问题讨论】:

    标签: android json android-intent android-recyclerview retrofit


    【解决方案1】:

    如果你想用你需要的动画从 RecyclerView 中移除项目:

    1) 从适配器中删除该项目。

    2) 调用适配器。notifyItemRemoved(int)。

    【讨论】:

    • 先生 .. 在此之后如何通过意图将其传递给另一个活动?
    • @sdfjklkjhgfdcvb 您可以从适配器获取数据,将其保存在一个包中,然后将其传递给另一个活动。stackoverflow.com/a/4429060/908821
    • @Potapov 那部分代码将进入主要活动或 PlaceApdater ?
    • @sdfjklkjhgfdcvb 这部分代码几乎可以在任何地方使用
    猜你喜欢
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 2018-05-23
    • 2022-01-08
    • 2018-05-03
    • 1970-01-01
    相关资源
    最近更新 更多