大佬教程收集整理的这篇文章主要介绍了具有多个视图的 Recyclerview,删除 addTextChangedListener() 不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个 androID 应用程序,我正在以编程方式更改部分 EditText
的值,手动更改 EditText
的值。
我在每个 addTextChangedListener()
上都添加了一个 EditText
。但在此之前,我已经为每个 TextWatcher
全局创建了 EditText
对象。
private TextWatcher quantityWatcher;
private TextWatcher priceWatcher;
private TextWatcher discountWatcher;
并定义它的 onBindVIEwHolder()
方法,所以每当我想删除或添加一个 TextChangedListener()
时,我都可以轻松完成。
在以编程方式更改任何 EditText 的值之前,我将使用 addTextChangedListener()
删除每个 TextWatcher 对象上的 removeTextChangedListener()
以避免单独调用该函数。更改值并重新注册监听器之后。
对于数量 EditText
quantityWatcher = new TextWatcher() {
@OverrIDe
public voID beforeTextChanged(CharSequence charSequence,int i,int i1,int i2) {
}
@OverrIDe
public voID ontextChanged(CharSequence charSequence,int i2) {
}
@OverrIDe
public voID afterTextChanged(Editable editablE) {
Log.d("SocialCodia","afterTextChanged: quantityWatcher Event Listener Called");
quantityEvent(holder);
}
};
对于折扣 EditText。
priceWatcher = new TextWatcher() {
@OverrIDe
public voID beforeTextChanged(CharSequence charSequence,"afterTextChanged: priceWatcher Event Listener Called");
priceEvent(holder);
}
};
销售价格 EditText
discountWatcher = new TextWatcher() {
@OverrIDe
public voID beforeTextChanged(CharSequence charSequence,"afterTextChanged: discountWatcher Event Listener Called");
discounTinputEvent(holder);
}
};
我在更改 EditText 值时调用的方法。
private voID priceEvent(VIEwHolder holder) {
Log.d("SocialCodia","PriceEvent Method Called");
unregisterTextWatcher(holder);
int @R_123_10586@lPrice = Integer.parseInt(holder.input@R_123_10586@lPrice.getText().toString().trim());
String sellPriceString = holder.inputSALEPrice.getText().toString().trim();
if (sellPriceString.trim().length()>0)
{
int sellPrice = Integer.parseInt(holder.inputSALEPrice.getText().toString().trim());
int discount = percentage(sellPrice,@R_123_10586@lPricE);
holder.inputSALEdiscount.setText(String.valueOf(discount));
}
else
{
holder.inputSALEdiscount.setText(String.valueOf(100));
}
registerTextWatchers(holder);
}
private voID quantityEvent(VIEwHolder holder)
{
Log.d("SocialCodia","quantityEvent Method Called");
unregisterTextWatcher(holder);
String quan = holder.inputSALEQuantity.getText().toString().trim();
String per = holder.inputSALEdiscount.getText().toString().trim();
int quantity;
int percentage;
if (quan == null || quan.length()<1 || quan.isEmpty())
quantity = 1;
else
quantity = Integer.parseInt(quan);
if (per==null || per.length()<1)
percentage = 0;
else
percentage = Integer.parseInt(per);
int price = Integer.parseInt(holder.tvProductPrice.getText().toString());
int finalPrice = price*quantity;
holder.input@R_123_10586@lPrice.setText(String.valueOf(finalPricE));
int SALEPrice = percentageDec(finalPrice,percentagE);
holder.inputSALEPrice.setText(String.valueOf(SALEPricE));
registerTextWatchers(holder);
}
private voID discounTinputEvent(VIEwHolder holder) {
Log.d("SocialCodia","discounTinputEvent Method Called");
unregisterTextWatcher(holder);
int @R_123_10586@lPrice = Integer.parseInt(holder.input@R_123_10586@lPrice.getText().toString().trim());
String per = holder.inputSALEdiscount.getText().toString().trim();
int percentage;
if (per==null || per.length()<1)
percentage = 0;
else
percentage = Integer.parseInt(per);
int price = percentageDec(@R_123_10586@lPrice,percentagE);
holder.inputSALEPrice.setText(String.valueOf(pricE));
registerTextWatchers(holder);
}
privatE int percentage(int partialValue,int @R_123_10586@lvalue) {
Log.d("SocialCodia","percentage Method Called");
Double partial = (doublE) partialValue;
Double @R_123_10586@l = (doublE) @R_123_10586@lValue;
Double per = (100 * partial) / @R_123_10586@l;
Double p = 100 - per;
return p.intValue();
}
privatE int percentageDec(int @R_123_10586@lValue,int per) {
Log.d("SocialCodia","percentageDec Method Called");
if (per == 0 || String.valueOf(per).length() < 0)
return @R_123_10586@lValue;
else {
Double @R_123_10586@l = (doublE) @R_123_10586@lValue;
Double perc = (doublE) per;
Double price = (@R_123_10586@l - ((perc / 100) * @R_123_10586@l));
Integer p = price.intValue();
return p;
}
}
每个条件、逻辑或方法都运行良好。但是当我在 recyclervIEw
中插入多个视图时。更改任何行 EditText
的值,但当前插入的视图会一次又一次地调用侦听器本身。
我试图找出确切的问题,但无法做到。
我的适配器类 AdapterSALEEditable.java
public class AdapterSALEEditable extends RecyclerVIEw.Adapter<AdapterSALEEditable.VIEwHolder> {
private Context context;
private List<ModelSALE> modelSALEList;
private String token;
private SharedPrefHandler sp;
private ModelUser user;
private Boolean discountFlag = false;
private Boolean priceEvenFlag = false;
private TextWatcher quantityWatcher;
private TextWatcher priceWatcher;
private TextWatcher discountWatcher;
public AdapterSALEEditable(Context context,List<ModelSALE> modelSALEs) {
this.context = context;
this.modelSALEList = modelSALEs;
sp = SharedPrefHandler.geTinstance(context);
user = sp.getUser();
token = user.getToken();
}
@NonNull
@OverrIDe
public VIEwHolder onCreateVIEwHolder(@NonNull VIEwGroup parent,int vIEwTypE) {
View view = LayoutInflater.from(context).inflate(R.layout.row_SALE_editable,parent,falsE);
return new VIEwHolder(vIEw);
}
@OverrIDe
public voID onBindVIEwHolder(@NonNull VIEwHolder holder,int position) {
ModelSALE SALE = modelSALEList.get(position);
int productID = SALE.getProductID();
int SALEID = SALE.getSALEID();
String productcategory = SALE.getProductcategory();
String productname = SALE.getProductname();
String productSize = SALE.getProductSize();
String productBrand = SALE.getProductBrand();
int productPrice = SALE.getProductPrice();
int productQuantity = SALE.getProductQuantity();
String productManufacture = SALE.getProductManufacture();
String productExpire = SALE.getProductExpire();
String createdAt = SALE.getCreatedAt();
holder.tvProductname.setText(productName);
holder.tvProductSize.setText("(" + productSize + ")");
holder.tvProductcategory.setText(productcategory);
holder.tvProductPrice.setText(String.valueOf(productPricE));
holder.input@R_123_10586@lPrice.setText(String.valueOf(productPricE));
holder.inputSALEQuantity.setText(String.valueOf(1));
holder.inputSALEPrice.setText(String.valueOf(productPricE));
holder.inputSALEdiscount.setText(String.valueOf(0));
holder.tvProductBrand.setText(productBrand);
holder.tvProductManufacture.setText(productManufacturE);
holder.tvProductExpire.setText(productExpirE);
holder.tvCount.setText(String.valueOf(position + 1));
holder.cvSell.setonLongClickListener(vIEw -> {
showdeletealert(holder,SALE,position);
return true;
});
quantityWatcher = new TextWatcher() {
@OverrIDe
public voID beforeTextChanged(CharSequence charSequence,int i2) {
}
@OverrIDe
public voID ontextChanged(CharSequence charSequence,int i2) {
}
@OverrIDe
public voID afterTextChanged(Editable editablE) {
Log.d("SocialCodia","afterTextChanged: quantityWatcher Event Listener Called");
quantityEvent(holder);
}
};
priceWatcher = new TextWatcher() {
@OverrIDe
public voID beforeTextChanged(CharSequence charSequence,"afterTextChanged: priceWatcher Event Listener Called");
priceEvent(holder);
}
};
discountWatcher = new TextWatcher() {
@OverrIDe
public voID beforeTextChanged(CharSequence charSequence,"afterTextChanged: discountWatcher Event Listener Called");
discounTinputEvent(holder);
}
};
registerTextWatchers(holder);
//End on create method
}
private voID registerTextWatchers(VIEwHolder holder) {
Log.d("SocialCodia","RegiString Listener");
holder.inputSALEQuantity.addTextChangedListener(quantityWatcher);
holder.inputSALEPrice.addTextChangedListener(priceWatcher);
holder.inputSALEdiscount.addTextChangedListener(discountWatcher);
}
private voID unregisterTextWatcher(VIEwHolder holder)
{
Log.d("SocialCodia","UnRegiString Listener");
holder.inputSALEQuantity.removeTextChangedListener(quantityWatcher);
holder.inputSALEPrice.removeTextChangedListener(priceWatcher);
holder.inputSALEdiscount.removeTextChangedListener(discountWatcher);
}
private voID priceEvent(VIEwHolder holder) {
Log.d("SocialCodia","PriceEvent Method Called");
unregisterTextWatcher(holder);
int @R_123_10586@lPrice = Integer.parseInt(holder.input@R_123_10586@lPrice.getText().toString().trim());
String sellPriceString = holder.inputSALEPrice.getText().toString().trim();
if (sellPriceString.trim().length()>0)
{
int sellPrice = Integer.parseInt(holder.inputSALEPrice.getText().toString().trim());
int discount = percentage(sellPrice,@R_123_10586@lPricE);
holder.inputSALEdiscount.setText(String.valueOf(discount));
}
else
{
holder.inputSALEdiscount.setText(String.valueOf(100));
}
registerTextWatchers(holder);
}
private voID quantityEvent(VIEwHolder holder)
{
Log.d("SocialCodia","quantityEvent Method Called");
unregisterTextWatcher(holder);
String quan = holder.inputSALEQuantity.getText().toString().trim();
String per = holder.inputSALEdiscount.getText().toString().trim();
int quantity;
int percentage;
if (quan == null || quan.length()<1 || quan.isEmpty())
quantity = 1;
else
quantity = Integer.parseInt(quan);
if (per==null || per.length()<1)
percentage = 0;
else
percentage = Integer.parseInt(per);
int price = Integer.parseInt(holder.tvProductPrice.getText().toString());
int finalPrice = price*quantity;
holder.input@R_123_10586@lPrice.setText(String.valueOf(finalPricE));
int SALEPrice = percentageDec(finalPrice,percentagE);
holder.inputSALEPrice.setText(String.valueOf(SALEPricE));
registerTextWatchers(holder);
}
private voID discounTinputEvent(VIEwHolder holder) {
Log.d("SocialCodia","discounTinputEvent Method Called");
unregisterTextWatcher(holder);
int @R_123_10586@lPrice = Integer.parseInt(holder.input@R_123_10586@lPrice.getText().toString().trim());
String per = holder.inputSALEdiscount.getText().toString().trim();
int percentage;
if (per==null || per.length()<1)
percentage = 0;
else
percentage = Integer.parseInt(per);
int price = percentageDec(@R_123_10586@lPrice,percentagE);
holder.inputSALEPrice.setText(String.valueOf(pricE));
registerTextWatchers(holder);
}
privatE int percentage(int partialValue,int @R_123_10586@lvalue) {
Log.d("SocialCodia","percentage Method Called");
Double partial = (doublE) partialValue;
Double @R_123_10586@l = (doublE) @R_123_10586@lValue;
Double per = (100 * partial) / @R_123_10586@l;
Double p = 100 - per;
return p.intValue();
}
privatE int percentageDec(int @R_123_10586@lValue,int per) {
Log.d("SocialCodia","percentageDec Method Called");
if (per == 0 || String.valueOf(per).length() < 0)
return @R_123_10586@lValue;
else {
Double @R_123_10586@l = (doublE) @R_123_10586@lValue;
Double perc = (doublE) per;
Double price = (@R_123_10586@l - ((perc / 100) * @R_123_10586@l));
Integer p = price.intValue();
return p;
}
}
private voID showdeletealert(VIEwHolder holder,ModelSALE SALE,int position) {
AlertDialog.builder builder = new AlertDialog.builder(context);
builder.settitle("Are you sure want to delete?");
builder.setmessage("You are going to delete " + SALE.getProductname() + ". The SALE Quantity of this product was " + SALE.getSALEQuantity() + " and the @R_123_10586@l price was " + SALE.getSALEPrice());
builder.setPositivebutton("delete",new DialogInterface.onClickListener() {
@OverrIDe
public voID onClick(DialogInterface dialogInterface,int i) {
deleteSoldProduct(SALE.getSALEID(),position);
}
});
builder.setNegativebutton("Cancel",int i) {
Toast.makeText(context,"deletion Canceled",Toast.LENGTH_SHORT).show();
}
});
builder.show();
}
private voID deleteSoldProduct(int sellID,int position) {
Call<ResponseDefault> call = apiclient.geTinstance().getAPI().deleteSoldProduct(sellID,token);
call.enqueue(new CallBACk<ResponseDefault>() {
@OverrIDe
public voID onResponse(Call<ResponseDefault> call,Response<ResponseDefault> responsE) {
if (response.issuccessful()) {
ResponseDefault responseDefault = response.body();
if (!responseDefault.isError()) {
TastyToast.makeText(context,responseDefault.getmessage(),Toast.LENGTH_SHORT,TastyToast.succesS);
Helper.playsuccess();
Helper.playVibrate();
modelSALEList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position,modelSALEList.size());
} else
TastyToast.makeText(context,TastyToast.ERROR);
} else
Toast.makeText(context,"request Isn't success",Toast.LENGTH_SHORT).show();
}
@OverrIDe
public voID onFailure(Call<ResponseDefault> call,Throwable t) {
t.printstacktrace();
}
});
}
public voID updateList(List<ModelSALE> List) {
modelSALEList = List;
notifyDataSetChanged();
}
@OverrIDe
public int getItemCount() {
return modelSALEList.size();
}
public class VIEwHolder extends RecyclerVIEw.VIEwHolder {
private TextVIEw tvProductname,tvProductSize,tvProductcategory,tvSALETime,tvProductPrice,tvProductBrand,tvProductManufacture,tvProductExpire,tvCount;
private EditText inputSALEQuantity,inputSALEdiscount,inputSALEPrice,input@R_123_10586@lPrice;
private CardVIEw cvSell;
public VIEwHolder(@NonNull VIEw itemVIEw) {
super(itemVIEw);
tvProductname = itemVIEw.findVIEwByID(R.ID.tvProductName);
tvProductSize = itemVIEw.findVIEwByID(R.ID.tvProductSizE);
tvProductcategory = itemVIEw.findVIEwByID(R.ID.tvProductcategory);
tvSALETime = itemVIEw.findVIEwByID(R.ID.tvSALETimE);
tvProductPrice = itemVIEw.findVIEwByID(R.ID.tvProductPricE);
inputSALEQuantity = itemVIEw.findVIEwByID(R.ID.inputSALEQuantity);
inputSALEdiscount = itemVIEw.findVIEwByID(R.ID.inputSALEdiscount);
inputSALEPrice = itemVIEw.findVIEwByID(R.ID.inputSALEPricE);
tvProductBrand = itemVIEw.findVIEwByID(R.ID.tvProductBrand);
tvProductManufacture = itemVIEw.findVIEwByID(R.ID.tvProductManufacturE);
tvProductExpire = itemVIEw.findVIEwByID(R.ID.tvProductExpirE);
input@R_123_10586@lPrice = itemVIEw.findVIEwByID(R.ID.input@R_123_10586@lPricE);
tvCount = itemVIEw.findVIEwByID(R.ID.tvCount);
cvSell = itemVIEw.findVIEwByID(R.ID.cvSell);
}
}
}
我的片段。从我设置回收站视图的地方。 SellProductFragment.java
public class SellProductActivity extends AppCompatActivity {
private ImageVIEw ivCloseDialog;
private RecyclerVIEw recyclerVIEw;
private EditText inputSearchProduct;
private static List<ModelProduct> modelProductList;
private AdapterProductSALE adapterProductSALE;
privatE int productID;
private Actionbar actionbar;
@OverrIDe
protected voID onCreate(Bundle savedInstanceStatE) {
super.onCreate(savedInstanceStatE);
setContentVIEw(R.layout.activity_sell_product);
init();
actionbar = getSupportActionbar();
actionbar.settitle("Sell Product");
setRecyclerVIEw();
inputSearchProduct.addTextChangedListener(new TextWatcher() {
@OverrIDe
public voID beforeTextChanged(CharSequence charSequence,int i2) {
}
@OverrIDe
public voID afterTextChanged(Editable editablE) {
filter(editable.toString());
}
});
}
@OverrIDe
public Boolean onPrepareOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_close,menu);
return super.onPrepareOptionsMenu(menu);
}
@OverrIDe
public Boolean onoptionsItemSELEcted(@NonNull MenuItem item) {
int id = item.getItemID();
if (ID==R.ID.miClosE)
{
onBACkpressed();
}
return super.onoptionsItemSELEcted(item);
}
private voID filter(String text)
{
List<ModelProduct> p = new ArrayList<>();
for(ModelProduct SALE : modelProductList)
{
if (SALE.getProductname().tolowerCase().trim().contains(text.tolowerCase()))
{
p.add(SALE);
}
}
adapterProductSALE.updateList(p);
}
private voID setRecyclerVIEw() {
linearlayoutmanager layoutManager = new linearlayoutmanager(getApplicationContext());
recyclerVIEw.setLayoutManager(layoutManager);
modelProductList = DbHandler.getModelProductList();
adapterProductSALE = new AdapterProductSALE(SellProductActivity.this,modelProductList);
recyclerVIEw.setAdapter(adapterProductSALE);
}
private voID init() {
recyclerVIEw = findVIEwByID(R.ID.rvProducts);
inputSearchProduct = findVIEwByID(R.ID.inputSearchProduct);
modelProductList = new ArrayList<>();
}
}
我该如何解决这个问题。
-感谢您的帮助!
但是当我在 recyclerview 中插入多个视图时。更改除当前插入的视图之外的任何行 EditText 的值,一次又一次地调用侦听器本身。
嗯,一遍又一遍地重复侦听器复制的主要问题,这些侦听器存在于 onBindViewHolder()
中,因为每次要显示/回收/更改 RecyclerView
行时都会调用此方法/插入屏幕;每当您添加新项目时,这显然都会发生。
因此,可能的方法是在其他地方注册这些侦听器,这些侦听器将被调用一次,或者您想随时调用;即不是每次都回收行。
您可以在 ViewHolder
自身的 EditText's
构造函数中执行此操作。
挑战:我们如何知道用户修改了哪个 EditText
? .. 好像修改了一些 EditText
并且您回收了视图(即向上/向下滚动列表),您会看到该值在多行中被弄乱了。
这可以通过以下方式解决:
EditText
中的 @H_852_3@modelSALE 值...不是
确定你是否已经这样做了..反正这门课应该有
fields、getter 和 setter 对应于 EditTexts
字段,它们
我们有 (quantity
,discount
,& price
)。而这些领域应该
在 onBindViewHoder()
中设置以获取保存的值
行被回收。 @Override
public void onBindViewHolder(@NonNull ViewHolder holder,int position) {
ModelSALE SALE = modelSALEList.get(position);
// ...... rest of your code
holder.unregisterTextWatcher();
holder.inputSALEQuantity.setText(SALE.getQuantatiy());
holder.inputSALEDiscount.setText(SALE.getDiscount());
holder.inputSALEPrice.setText(SALE.getPrice());
holder.registerTextWatchers();
//End on create method
}
ViewHolder
获取 getAdapterPostion()
中的当前项目而且这种方法需要将所有与 EditText
观察者相关的观察者、字段和方法从 RecyclerViewAdapter
移动到 ViewHolder
并且每次更改这些 EditTexts
字段之前,您都需要取消注册文本 Watchers。
这里的适配器只是为了紧凑而进行了这些修改。
public class AdapterSALEEditable extends RecyclerView.Adapter<AdapterSALEEditable.ViewHolder> {
// ... your code
@Override
public void onBindViewHolder(@NonNull ViewHolder holder,int position) {
ModelSALE SALE = modelSALEList.get(position);
// ...... rest of your code
holder.unregisterTextWatcher();
holder.inputSALEQuantity.setText(SALE.getQuantatiy());
holder.inputSALEDiscount.setText(SALE.getDiscount());
holder.inputSALEPrice.setText(SALE.getPrice());
holder.registerTextWatchers();
//End on create method
}
public class ViewHolder extends RecyclerView.ViewHolder {
private TextView tvProductName,tvProductSize,tvProductCategory,tvSALETime,tvProductPrice,tvProductBrand,tvProductManufacture,tvProductExpire,tvCount;
private EditText inputSALEQuantity,inputSALEDiscount,inputSALEPrice,input@R_123_10586@lPrice;
private CardView cvSell;
private TextWatcher quantityWatcher;
private TextWatcher priceWatcher;
private TextWatcher discountWatcher;
private void registerTextWatchers() {
Log.d("SocialCodia","RegiString Listener");
inputSALEQuantity.addTextChangedListener(quantityWatcher);
inputSALEPrice.addTextChangedListener(priceWatcher);
inputSALEDiscount.addTextChangedListener(discountWatcher);
}
private void unregisterTextWatcher() {
Log.d("SocialCodia","UnRegiString Listener");
inputSALEQuantity.removeTextChangedListener(quantityWatcher);
inputSALEPrice.removeTextChangedListener(priceWatcher);
inputSALEDiscount.removeTextChangedListener(discountWatcher);
}
private void priceEvent() {
Log.d("SocialCodia","PriceEvent Method Called");
unregisterTextWatcher();
int @R_123_10586@lPrice = Integer.parseInt(input@R_123_10586@lPrice.getText().toString().trim());
String sellPriceString = inputSALEPrice.getText().toString().trim();
if (sellPriceString.trim().length() > 0) {
int sellPrice = Integer.parseInt(inputSALEPrice.getText().toString().trim());
int discount = percentage(sellPrice,@R_123_10586@lPricE);
inputSALEDiscount.setText(String.valueOf(discount));
} else {
inputSALEDiscount.setText(String.valueOf(100));
}
registerTextWatchers();
}
private void quantityEvent() {
Log.d("SocialCodia","quantityEvent Method Called");
unregisterTextWatcher();
String quan = inputSALEQuantity.getText().toString().trim();
String per = inputSALEDiscount.getText().toString().trim();
int quantity;
int percentage;
if (quan == null || quan.length() < 1 || quan.isEmpty())
quantity = 1;
else
quantity = Integer.parseInt(quan);
if (per == null || per.length() < 1)
percentage = 0;
else
percentage = Integer.parseInt(per);
int price = Integer.parseInt(tvProductPrice.getText().toString());
int finalPrice = price * quantity;
input@R_123_10586@lPrice.setText(String.valueOf(finalPricE));
int SALEPrice = percentageDec(finalPrice,percentagE);
inputSALEPrice.setText(String.valueOf(SALEPricE));
registerTextWatchers();
}
private void discounTinputEvent() {
Log.d("SocialCodia","discounTinputEvent Method Called");
unregisterTextWatcher();
int @R_123_10586@lPrice = Integer.parseInt(input@R_123_10586@lPrice.getText().toString().trim());
String per = inputSALEDiscount.getText().toString().trim();
int percentage;
if (per == null || per.length() < 1)
percentage = 0;
else
percentage = Integer.parseInt(per);
int price = percentageDec(@R_123_10586@lPrice,percentagE);
inputSALEPrice.setText(String.valueOf(pricE));
registerTextWatchers();
}
privatE int percentage(int partialValue,int @R_123_10586@lvalue) {
Log.d("SocialCodia","percentage Method Called");
Double partial = (doublE) partialValue;
Double @R_123_10586@l = (doublE) @R_123_10586@lValue;
Double per = (100 * partial) / @R_123_10586@l;
Double p = 100 - per;
return p.intValue();
}
privatE int percentageDec(int @R_123_10586@lValue,int per) {
Log.d("SocialCodia","percentageDec Method Called");
if (per == 0 || String.valueOf(per).length() < 0)
return @R_123_10586@lValue;
else {
Double @R_123_10586@l = (doublE) @R_123_10586@lValue;
Double perc = (doublE) per;
Double price = (@R_123_10586@l - ((perc / 100) * @R_123_10586@l));
Integer p = price.intValue();
return p;
}
}
public ViewHolder(@NonNull View itemView) {
super(itemView);
// Rest of your code
// Text Watchers
quantityWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence,int i,int i1,int i2) {
}
@Override
public void ontextChanged(CharSequence charSequence,int i2) {
}
@Override
public void afterTextChanged(Editable editablE) {
Log.d("SocialCodia","afterTextChanged: quantityWatcher Event Listener Called");
quantityEvent();
}
};
priceWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence,"afterTextChanged: priceWatcher Event Listener Called");
priceEvent();
}
};
discountWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence,"afterTextChanged: discountWatcher Event Listener Called");
discounTinputEvent();
}
};
registerTextWatchers();
}
}
}
以上是大佬教程为你收集整理的具有多个视图的 Recyclerview,删除 addTextChangedListener() 不起作用全部内容,希望文章能够帮你解决具有多个视图的 Recyclerview,删除 addTextChangedListener() 不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。