【问题标题】:Java get id of textView or Button by click with android studioJava 通过点击 android studio 获取 textView 或 Button 的 id
【发布时间】:2021-02-20 04:08:29
【问题描述】:

如果我点击它而不设置预点击事件,我想获得一个文本视图或按钮 ID。我该怎么做?

例如:

用户点击文本视图

比:

接收 R.id.textview3

【问题讨论】:

    标签: java android-studio button textview click


    【解决方案1】:

    使用循环并增加 id 并将其设置为 TextView

    【讨论】:

      【解决方案2】:

      id 是一个整数类型,你可以把它存储为一个变量

      int id = R.id.textview3;
      textview.setOnClickListner{
          //use id variable here for example
          fun(id);
      }
      

      【讨论】:

        猜你喜欢
        • 2017-05-15
        • 1970-01-01
        • 2013-08-18
        • 1970-01-01
        • 1970-01-01
        • 2012-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多