Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare string stored in string resource in android?

Tags:

android

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>
like image 319
napster Avatar asked Jul 27 '12 06:07

napster


Video Answer


1 Answers

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>
like image 161
mainu Avatar answered Nov 14 '22 23:11

mainu