大家好。
我正在将自定义布局夸大为对象的行。
一切正常,除了我无法将Click / LongClick设置为该行。
这就是我所做的。
Layout_BatchRow batchRow = new Layout_BatchRow(this);
batchRow.New(batchObject);
batchRow.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(final View v) {
. . .
}
});
batchRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
. . .
}
});
以下是自定义布局类:
public class Layout_BatchRow extends RelativeLayout {
public Layout_BatchRow(Context context) {
super(context);
inflate(getContext(), R.layout.batch_row, this);
. . .
}
}
这是布局XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tool="http://schemas.android.com/tools"
android:clickable="true"
android:focusable="true"
android:longClickable="true"
tool:context=".Layout_BatchRow">
. . .
</RelativeLayout>
调试时未达到侦听器。
有什么主意吗?
答案 0 :(得分:1)
我认为您不需要添加此内容:
android:clickable="true"
android:focusable="true"
android:longClickable="true"