In my XML, I have a TableLayout with only 1 TableRow i.e. the heading. Other all rows I add dynamically setting BackgroundColor (LTGray) for TableRow & TextColor for TextViews in it . I also handle click event on each row.
private void createView(TableRow tr, TextView tv, String data, int rowId) {
tv.setText(data);
//tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tv.setTextColor(Color.BLACK);
tv.setPadding(20, 0, 0, 0);
tr.setPadding(0, 1, 0, 1);
tr.setBackgroundColor(Color.LTGRAY);
tr.setId(rowId);
tr.setClickable(true);
tr.setOnClickListener(this);
tr.addView(tv);
}
Reg selection : I want to change the BackgroundColor of TableRow lets say Yellow. So if 1st row is selected it bgColor should be Yellow. Then if 3rd row is selected the 1st row's color should turn to LTGray.
And if anywhere out of the Rows is clicked, then the selected Row (if at all) should also be de-selected. For this do I have to add the main layout clickListener OR make the row select again and it turns deselected ?
Can selector (state list drawable) work for both the ways or I got to handle it programmatically. What sort of Drawable should I use to setBackgroundDrawable in my Java Code to se the statelist drawable ?
I believe like other components for TableRow also onClick will also take care of onTouch. Please correct me if am wrong. As want to handle the same feature with touching the row also.
What is the best way to achieve the goal ? Any help is highly appreciated.