我在RelativeLayout 中有一个手动创建的TextView 数组。所有显示完美,除了:onclicklistener not work 代码:
private RelativeLayout mRLMain;
private TextView [] mTV;
private OnClickListener mTextOnClickListener;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRLMain = (RelativeLayout) findViewById(R.id.rlMainGame);
mTV = new TextView[20];
mSqueareLayout = new RelativeLayout.LayoutParams(mSquareWidth,mSquareWidth);
for (i = 0; i < 20; i++) {
mTV [i] = new TextView(MainActivity.this);
mTV [i].setBackgroundColor(Color.RED);
mTV [i].setTextColor(Color.WHITE);
mTV [i].setX(i+100);
mTV [i].setId(i);
mTV [i].setOnClickListener(mTextOnClickListener);
mRLMain.addView(mTV [i], mSqueareLayout);
}
mTextOnClickListener = new OnClickListener() {
@Override
public void onClick(View view) { Log.d("XXX","CLICK"); }
};
}
尝试
mTV [i].setFocusable(false);
mTV [i].setFocusableInTouchMode(false);
mTV [i].setClickable(true);
mTV [i].setDuplicateParentStateEnabled(false);
什么都没有: - 没有错误 - 没有日志