android - TextView 是 onfocus 窃取了 onclick 事件吗?

标签 android android-layout android-widget textview android-ui

当我为我的 TextView 设置点击监听器时,初始点击不会触发事件。这是 TextView :

<TextView 
  style="@android:style/Widget.EditText"
  android:id="@+id/my_text_area"
  android:layout_width="0dip"
  android:layout_height="wrap_content"
  android:textColorHint="@color/text_hint"
  android:singleLine="true"
  android:focusable="true"
  android:focusableInTouchMode="true"
  android:clickable="true"
  android:padding="10dip"
  android:background="@android:color/transparent"
  android:layout_weight="1"
  ></TextView>

// OnCreate:
TextView link = (TextView)findViewById(R.id.my_text_area);
// "this" is my Activity that implements OnClickListener
link.setOnClickListener(this); 

void OnClick(view v) {
    //only gets fired after the first time
}

当我点击 TextView 时,会发生以下情况:

点击 1. textview 获得焦点
点击 2. 触发 OnClick

我也需要点击 1 来触发它

最佳答案

你非常接近......

link.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // do something fancy
    }
});

关于android - TextView 是 onfocus 窃取了 onclick 事件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5887215/

相关文章:

java - 有没有办法将 firestore 中的数据值存储到数组中?

java - 错误的 xml block 3 线性布局和 2 日历

android - "eglConfig not initialized"错误,但我没有使用 openGl

Android对齐表格的内容

java - 按 "back button"退出后 Android 应用程序崩溃

java - 如何在android中设置fm radio 的频率?

android - DragSortListView 在用户确认后删除项目

android - 如何将 NDK 库导入 Eclipse

java - 如何修复 "Exception raised during rendering: android.view.View cannot be cast to android.view.ViewGroup"

java - 奇怪的用户崩溃报告: Null Pointer exception for something that is definitely there