praew_z
praew_z

Reputation: 175

Check value in text view

I have a if condition for check value in textview but it still happen only else condition

what I did wrong, why it doesn't have if condition even if I have set lang=space

private void setLangTitle() {
    lang.setText(" ");
    db.open();
    Cursor cc = db.getLangAct();
    cc.moveToFirst();
    int index = cc.getColumnIndex(DBAdapter.KEY_LANG);
    while (cc.isAfterLast() == false) {

        if(lang.equals(" ")){
            lang.append("p"+cc.getString(index));
            cc.moveToNext();
        }
        else {
            lang.append("/" + cc.getString(index));
            cc.moveToNext();
        }
    }
    db.close();
}

Upvotes: 0

Views: 5994

Answers (3)

RoflcoptrException
RoflcoptrException

Reputation: 52247

I assume that lang is your TextView object? Then you should use lang.getText().toString()

Upvotes: 2

Federico klez Culloca
Federico klez Culloca

Reputation: 27149

you should use

if(lang.getText()equals(" ")){
    ...
}

You were not comparing texts, you were comparing objects. And, of course, a TextView doesn't (shouldn't) compare equal to a String.

Upvotes: 1

eldarerathis
eldarerathis

Reputation: 36243

You're currently checking if lang is equal to a space character. If lang is a TextView, than it will not be equal to the space character because it is a TextView object, not a string. You probably want to test if the text being displayed on lang is equal to the space character, which would be something along the lines of:

if (lang.getText().toString().equals(" ")) {
    ...
}

Upvotes: 6

Related Questions