我正在尝试更改项目bgcolor的recyclerview值以及获取该位置的值。我能够获取这些值并更改它们bgcolor,但我无法正确执行它们。我面临以下问题:1.第一个位置项目的背景总是改变:当我点击它时我想改变它。2.如果我能够bgcolor相应地更改,则不会获取值。
这是我的代码:recyclerview 的适配器类
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyAd> {
private static Clickitem clickitem;
private ArrayList<String> names = new ArrayList<>();
private Context context;
private int row ;
String defaulter;
List<Item> items;
boolean isSeleceted = false;
private int selectedPosition = -1;
private String onlygps, onlysid, onlygpsnew, onlygpsnewer;
private SparseBooleanArray selectedItems = new SparseBooleanArray();
@NonNull
@Override
public MyAd onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(context).inflate(R.layout.list_recycler, viewGroup, false);
return new MyAd(view);
}
MyAdapter(ArrayList<String> names, Context context) {
this.names = names;
this.context = context;
clickitem = (Clickitem) context;
}
public static Clickitem getClickitem() {
return clickitem;
}
public static void setClickitem(Clickitem clickitem) {
MyAdapter.clickitem = clickitem;
}
@Override
public void onBindViewHolder(@NonNull final MyAd myAd, final int i) {
String full = names.get(i);
onlygps = full.substring(0, full.indexOf("/"));
onlysid = full.substring(full.lastIndexOf("/") + 1);
myAd.GPSname.setText(onlygps);
myAd.logs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String full = names.get(i);
onlygpsnew = full.substring(0, full.indexOf("/"));
Intent intent = new Intent(context, LogsHistory.class);
intent.putExtra("GPS", onlygpsnew);
context.startActivity(intent);
}
});
if (row == i) {
myAd.layout.setBackgroundColor(Color.YELLOW);
} else {
myAd.layout.setBackgroundColor(Color.WHITE);
}
}
白板的微信
相关分类