I have a button on which (like) is written from string resource, on click I want to toggle like to unlike & vice verse.
How to compare button contain like or unlike from string resource?
My string.xml contains
<string name="like">Like</string>
<string name="unlike>unlike</string>
Try this..
bt.setText(getString(R.string.txt1));
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
myStr = bt.getText().toString();
if((myStr.equals(getString(R.string.txt1)))) {
bt.setText(getString(R.string.txt2));
} else if ((myStr.equals(getString(R.string.txt2)))) {
bt.setText(getString(R.string.txt1));
}
}
});
In string.xml
<string name="txt1">11111111111</string>
<string name="txt2">2222222222222222</string>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With