Cla*_*reG 4 android tablelayout tablerow android-tablelayout
祝大家有个美好的一天。
我的每一行都有TableLayout三个TextViews。是否仍然可以添加OnClickListener到整行?我想更改所选行的背景颜色。我已经设定OnClickListener为TableRow通过执行以下,但背景颜色不会改变:
for(int i =0; i < rowAmount; i++)
{
TableRow tr= new TableRow(this);
TextView rmNo;
TextView s;
TextView p;
rmNo = new TextView(this);
s = new TextView(this);
p = new TextView(this);
rmNo.setText("" + roomNumbers.get(i).toString());
s.setText("" + statuses.get(i).toString());
p.setText("" + priorities.get(i).toString());
tr.addView(rmNo);
tr.addView(s);
tr.addView(p);
tr.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
tr.setBackgroundColor(color.holo_blue_light);
}
});
tblContent.addView(tr);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在以编程方式创建 TableRows 和 TextViews,因为它们的数据是从数据库中检索的。
这是 XML:
<ScrollView
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tblTitles">
<TableLayout
android:id="@+id/tblContent"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ob">
</TableLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
任何帮助/想法将不胜感激。
已经查找的来源:
我测试了它,现在它工作正常,尝试使用
tr.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
v.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_light));
}
});
Run Code Online (Sandbox Code Playgroud)
反而...