[英]Dynamic TextView onClickListener Android
I'm adding an onClickListener
to a dynamic TextView
with a CompoundDrawable
and it doesnt seem to be working. 我将
onClickListener
添加到带有CompoundDrawable
的动态TextView
,它似乎不起作用。
CODE 码
for (Product p: mProductList) {
...
TextView textView = new TextView(this);
if (bmp != null) {
Drawable d = new BitmapDrawable(getResources(), bmp);
textView.setText(name);
textView.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
textView.setPadding(5, 0, 5, 0);
textView.setTag(unique);
textView.setClickable(true);
textView.setOnClickListener(mProductListener);
mProductCarousel.addView(textView, sortOrder);
}
}
mProductListener = new OnClickListener() {
@Override
public void onClick(View v) {
Log.v("TESTING", "CLICKED");
String productId = String.valueOf(v.getTag());
Log.v("PRODUCT ID", productId);
}
};
The TextView
with Drawable
are added to the layout with no problem, but the click event is not firing. 带有
Drawable
的TextView
Drawable
地添加到布局中,但是click事件没有触发。 I never receive either Log message. 我从未收到任何日志消息。 Any help is appreciated.
任何帮助表示赞赏。
I'm not sure. 我不确定。 This is just a hunch let me know if it pays of:
这只是预感,让我知道是否值得:
if (bmp != null) {
Drawable d = new BitmapDrawable(getResources(), bmp);
textView.setText(name);
textView.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
textView.setPadding(5, 0, 5, 0);
textView.setTag(unique);
textView.setClickable(true);
textView.setFocusableInTouchMode(true);
textView.setOnClickListener(mProductListener);
mProductCarousel.addView(textView, sortOrder);
}
If it doesn't try the alternative: 如果没有尝试替代方法:
textView.setFocusable(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.