我怎样在一个onclicklistener添加到tablerow的? [英] How do I add an onclicklistener to a tablerow?
本文介绍了我怎样在一个onclicklistener添加到tablerow的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能一个onclicklistener添加到Android上tablerow的?
我动态添加这些行,并希望能够打开一个新的屏幕,当用户点击不同的行。
下面是我的code以添加一行。
TR的TableRow =新的TableRow(本);
TableLayout.LayoutParams tableRowParams =新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 =新的TextView(本);
tmake.setText(Html.fromHtml(&所述; H1>中+与& NBSP;&放大器; NBSP;&放大器; NBSP;&放大器; NBSP;&放大器; NBSP;+ NewText +&下; / H1>中+&下峰; br />中));
tr.addView(tmake);
视图V =新的视图(本);
v.setLayoutParams(新TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,1));
v.setBackgroundColor(Color.rgb(51,51,51));
tl.addView(五);
解决方案
筛选; - )
tableRow.setClickable(真);
tableRow.setOnClickListener(onClickListener);
Is it possible to add an onclicklistener to a tablerow in Android?
I am dynamically adding these rows, and want to be able to open a new screen when a user click on a different row.
Here is my code to add a row.
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>" + " " + 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);
解决方案
Like this ;-)
tableRow.setClickable(true);
tableRow.setOnClickListener(onClickListener);
这篇关于我怎样在一个onclicklistener添加到tablerow的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文