Hello i am trying to set a content description to my button buy when i try to access to it the value that return to me is null.
Here is the code of the button.
//This is the button of the payment.
ImageButton make_pay = new ImageButton(this);
make_pay.setBackgroundResource(R.drawable.add_product);
makePay.addView(make_pay);
makePay.setContentDescription("Precio");
This is the code that i use to access:
make_pay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View makepay) {
LinearLayout wrap_area = (LinearLayout)findViewById(R.id.division2);
TextView test = new TextView(FrontActivity.this);
wrap_area.addView(test);
if (makepay.getContentDescription() == null){
test.setText("Precio:1");
}else{
test.setText(makepay.getContentDescription().toString());
}
});
}
You are setting the content description to makePay object (whatever it is, probabbly a ViewGroup). But then, you are setting the listener to the make_pay ImageButton, which is the one received by the listener arguments. Thus, it’s content description is not the one assigned to the other object.
Try changing this:
with this:
Anyway, try not to name your objects in such a similar way. It could lead to big confussions.