开发者

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.appen开发者_如何学God("p"+cc.getString(index));
            cc.moveToNext();
        }
        else {
            lang.append("/" + cc.getString(index));
            cc.moveToNext();
        }
    }
    db.close();
}


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(" ")) {
    ...
}


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜