我已经尝试过多次询问这个问题,但所有其他关于工作的报告似乎与我的相同,除了我的不起作用。它编译并运行并且不会崩溃,但它根本不做它应该做的事情。在代码中,“Alpha”错误日志不会出现,因此它无法识别它已被点击。
这是相关的代码片段。有任何想法吗?
for(int i=0; i<[big long statement]; ++i)
{
final TextView resourceText= new TextView(ctx);
resourceText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
resourceText.setText([big long statement]);
resourceText.setTextSize(18);
resourceText.setClickable(true);
resourceText.setFocusable(false);
resourceText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("Alpha", "Alpha");
resourceText.setTextColor(Color.RED);
}
});
scrollLinearLayout.addView(resourceText);
}
这是创建 scrollLinearLayout 的地方
//Add Linear Layout for the scrollview
scrollLinearLayout = new LinearLayout(ctx);
scrollLinearLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));
scrollLinearLayout.setOrientation(LinearLayout.VERTICAL);
//scrollLinearLayout.setId(MyR.Ids.ROOMDIALOGFRAGMENTLL_ID);
resourceScrollView.addView(scrollLinearLayout);
谢谢