开发者

setting textview visibility to GONE when there is no text to show

i have a listview in which i have 2 textviews, one of these textview contains zero text by default, but can be changed by the user. the problem is that i need to do so when the textview is empty the visibility of it is set to GONE. i have 2 idea开发者_JAVA技巧s of how this might work, either defining it in xml or defining it in the database somehow.

public long createDate(String date) {
    ContentValues initialValues1 = new ContentValues();
    initialValues1.put(KEY_DATE, date);
    initialValues1.put(KEY_TIMESTAMP, "00:00");

    if(text==""){
       initialValues1.put(KEY_DICTTAG,View.GONE); //this does NOT work
    }else{
       initialValues1.put(KEY_DICTTAG,text);
    }

    initialValues1.put(KEY_DICTALARMTIME, "0");
    initialValues1.put(KEY_DICTLISTIMAGE, R.drawable.list_icon);
    return mdiktationsDb.insert(DATABASE_TABLE, null, initialValues1);
}

i know the textview wont be seen by the user when there is no text, but i need it to not be seen by the system so to speak. this is because i need the timestamp textview to be centerd in the relative layout when there is no text in the dicttag textview. i could not post the xml layout because i do not have any room


It is a little unclear what the actual problem is but here goes....

First, are you sure that your if statement is working properly? You are comparing a String in Java with ==. I don't know where text is but use if (text.equalsIgnoreCase("")) instead.

Second, TextView.setVisibility(View.GONE) on your TextView should work as intended assuming you are handling it on the main UI thread. You can always override your ListView adapter and make a custom adapter and do your visibility operations there for each item in the ListView. There are plenty of posts and tutorials for doing that.


txt.setVisibility(View.GONE) for hide txt.setVisibility(View.VISIBLE); for show


Try if (text.equals ("")) instead of if (text == "")

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜