вот какое-то объяснение, что я обычно делал
вид установки с адаптером
private ArrayAdapter<String> arrayAdapter;
private ArrayList<String> listPName = new ArrayList<>();
private void showBluetoothPrinters() {
arrayAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1, listPName) {
@NonNull
@Override
public View getView(int position, View convertView, @NotNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView tv = view.findViewById(android.R.id.text1);
tv.setPadding(padding * 3, 0, padding * 3, 0);
return view;
}
};
lvPrinter.setAdapter(arrayAdapter);
}
затем вызвать notifyDataSetChanged () после обновления некоторых данных
Set<BluetoothDevice> mPairedDevices = mBluetoothAdapter.getBondedDevices();
if (mPairedDevices.size() > 0) {
for (BluetoothDevice mDevice : mPairedDevices) {
listPName.add(mDevice.getName());
}
}
if (arrayAdapter != null){
arrayAdapter.notifyDataSetChanged();
}
не знаю, ожидаете ли вы этого
Я добавляю некоторые из фрагментов вызовов notifydatasetchage в адаптер
@Override
public void onBindViewHolder(@NonNull VH holder, int position) {
int amount = mListData.get(position);
holder.tvAmount.setText(String.valueOf(amount));
holder.tvText.setText(decimalFormat.format(amount));
holder.itemView.setOnClickListener(v -> {
if (mListener != null){
mListener.onAmountTapped(amount);
}
tempSelected = position;
notifyDataSetChanged();
});
if (position == tempSelected){
holder.containerView.setBackground(mContext.getResources().getDrawable(R.drawable.rp_shadow_select));
} else {
holder.containerView.setBackground(mContext.getResources().getDrawable(R.drawable.rp_shadow));
}
}