gpt4 book ai didi

java - 单击 recyclerview 中的列表之一时如何关闭 Activity ?

转载 作者:行者123 更新时间:2023-11-30 12:04:19 24 4
gpt4 key购买 nike

我的 android studio 上有一个带适配器类的 recyclerview,如何在单击 recyclerview 中的列表之一时关闭 Activity ?

private void tampilLoker() {
ApiServices api = InitRetrofit.getInstance();
Call<ResponseLoker> beritaCall = api.request_show_all_loker();
beritaCall.enqueue(new Callback<ResponseLoker>() {
@Override
public void onResponse(Call<ResponseLoker> call, Response<ResponseLoker> response) {
if (response.isSuccessful()){
Log.d("response api", response.body().toString());
List<LokerItem> data_loker = response.body().getLoker();
boolean status = response.body().isStatus();
if (status){
AdapterBerita adapter = new AdapterBerita(LowonganKerja.this, data_loker);
recyclerView.setAdapter(adapter);
} else {
Toast.makeText(LowonganKerja.this, "Tidak ada Lowongan untuk saat ini", Toast.LENGTH_SHORT).show();
}
}
}

最佳答案

结束Activity很简单。调用 finish() 函数

private void tampilLoker() {
ApiServices api = InitRetrofit.getInstance();
Call<ResponseLoker> beritaCall = api.request_show_all_loker();
beritaCall.enqueue(new Callback<ResponseLoker>() {
@Override
public void onResponse(Call<ResponseLoker> call, Response<ResponseLoker> response) {
if (response.isSuccessful()){
Log.d("response api", response.body().toString());
List<LokerItem> data_loker = response.body().getLoker();
boolean status = response.body().isStatus();
if (status){
AdapterBerita adapter = new AdapterBerita(LowonganKerja.this, data_loker);
recyclerView.setAdapter(adapter);
//If you want to close your activity here then call finish func here
finish();
} else {
Toast.makeText(LowonganKerja.this, "Tidak ada Lowongan untuk saat ini", Toast.LENGTH_SHORT).show();
}
}
}

如果您在您的适配器类中,则在以下 onclick 事件调用中

((YourActivity) context).finish();

关于java - 单击 recyclerview 中的列表之一时如何关闭 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57201382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com