【问题标题】:How to use a string to control a setVisibility - Android如何使用字符串来控制 setVisibility - Android
【发布时间】:2013-07-20 07:47:38
【问题描述】:

我正在尝试控制我的适配器中的 setVisibility 以消除由空 TextViews 引起的间隙,但我无法确定如何使用我的方法来控制它。 我试过这个,然后意识到它不起作用,因为没有 View int。

date2.setVisibility(song.get(CustomizedListView.KEY_DATE2VIS));

我使用的方法如何控制可见性?这是我用来通过互联网向我的 TextViews 提供文本的文件。

在线托管的 XML 文件:

<games_list>
    <game>
        <id>1</id>
       <title>Grand Theft Auto 5</title>
       <date1>17th September 2013</date1>
       <date2/>
       <date3/>
       <platforms>360, PS3</platforms>
       <thumb_url>
           http://launchpadsoftware.webs.com/ReleaseDates%20Web%20Data/gta5thumb.jpg
       </thumb_url>
    </game>
    <game>
        <id>2</id>
       <title>Grand Theft Auto 5</title>
       <date1>17th September 2013</date1>
       <date2/>
       <date3/>
       <platforms>360, PS3</platforms>
       <thumb_url>
           http://api.androidhive.info/music/images/eminem.png
       </thumb_url>
    </game>
</games_list>

这非常适合设置适配器中所需的字符串,但我需要通过文件手动控制一些 TextView 的可见性。

【问题讨论】:

    标签: android string textview adapter visibility


    【解决方案1】:

    您需要在传递的数据和 android 视图可见性属性之间进行映射。我的意思是制作这样的地图

    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("visible", View.VISIBLE);
    map.put("gone", View.GONE);
    map.put("invisible", View.INVISIBLE);
    

    并在您的 XML 文件中传递“可见”、“消失”或“不可见”。然后使用date2.setVisibility(map.get(song.get(CustomizedListView.KEY_DATE2VIS))) 设置适当的可见性。

    【讨论】:

    • 啊,这更有意义。稍后我将不得不尝试它,如果它有效我会接受你的答案。
    猜你喜欢
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多