【问题标题】:Android- I want to set the visibilty of a textView in a listview row on clicking the button in the same listrowAndroid-我想在单击同一列表行中的按钮时在列表视图行中设置文本视图的可见性
【发布时间】:2012-04-12 03:58:48
【问题描述】:

[TextView1] [TextView2] [按钮]


列表行包含 2 个 TextView 和 1 个 Button。

最初 [TextView2] 的可见性设置为 View.GONE。

  1. 要求在连续单击 [Button] 时,应将同一行的 [TextView2] 的可见性设置为 View.VISIBLE
  2. 接下来单击 [Button] 应将 [TextView2] 的可见性设置为 View.GONE。即在单击 [Button] 时,应检查 [TextView2] 的可见性,并将其当前可见性更改为相反的可见性状态
  3. 即对于每次单击 [Button],如果 [TextView2] 可见,则使其不可见,反之亦然。

【问题讨论】:

    标签: android android-listview


    【解决方案1】:

    我有 2 个问题要问你:
    - 您的活动是 ListActivity 吗?
    - 你的列表适配器是什么?开箱即用还是定制?

    --
    更正:

    final Button button1 = (Button)findViewById(R.id.button1);
    final TextView textView2 = (Button)findViewById(R.id.textView2);
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (textView2.getVisibility()== View.VISIBLE) textView2.setVisibility(View.GONE);
            if (textView2.getVisibility()== View.GONE) textView2.setVisibility(View.VISIBLE);             
    
        }
    });
    

    【讨论】:

      【解决方案2】:

      这样的东西应该可以工作

          final Button button1 = (Button)findViewById(R.id.button1);
          final TextView textView2 = (Button)findViewById(R.id.textView2);
          button1.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  if (textView2.getVisibility() == View.VISIBLE) textView2.setVisibility(View.GONE);
                  if (textView2.getVisibility() == View.GONE) textView2.setVisibility(View.VISIBLE);              
      
              }
          });
      

      【讨论】:

      • 将 textView2.VISIBLE 更改为 textView2.getVisibility() 并使用 View.GONE 和 View.INVISIBLE 等常量而不是 0 和 1。否则会令人困惑。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 2015-12-05
      相关资源
      最近更新 更多