如何在tablerow中添加onclicklistener?

use*_*813 0 android

是否可以在Android中的tablerow中添加onclicklistener?

我正在动态添加这些行,并希望能够在用户单击其他行时打开新屏幕.

这是我添加行的代码.

TableRow tr = new TableRow(this);
TableLayout.LayoutParams tableRowParams= new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=20;
int topMargin=10;
int rightMargin=15;
int bottomMargin=20;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(tableRowParams);
TextView tmake=new TextView(this);
tmake.setText(Html.fromHtml("<H1>" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + NewText + "</H1>" +  "<br />"));
tr.addView(tmake); 
View v = new View(this);
v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
v.setBackgroundColor(Color.rgb(51, 51, 51));
tl.addView(v);
Run Code Online (Sandbox Code Playgroud)

小智 7

像这样 ;-)

tableRow.setClickable(true);
tableRow.setOnClickListener(onClickListener);
Run Code Online (Sandbox Code Playgroud)