I am working with a grid of a table built using a custom list with a fixed row of headers.
When a user clicks on one of the fixed header cells, the entire data table is sorted in that particular column.
I developed how to change the text of a clicked header cell by adding an up or down arrow to an existing header / column header (see Code below).
However, I also need to change the text of all the other column header cells in the data table to remove any existing up or down arrows from these other header cells.
The problem I ran into is this: how to find the view ids of these other column header cells at runtime.
Please note that these view identifiers cannot be found by searching for a specific TextView identifier from the xml layout, since all table header cells are created using a common TextView identifier called text1 (see the linear layout code used for the table heading below):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/item_table1_header" android:gravity="center" android:orientation="vertical" > <TextView android:id="@android:id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" />
The following is the getView code used to create the table cells, which also includes the built-in OnClickListener. Note that the header line of the fixed table is numbered -1.
I will need to add code to change the text of existing header cells in a section labeled βTODOβ as soon as I can identify their existing TextView identifiers:
@Override public View getView(final int row, final int column, View converView, ViewGroup parent) { if (converView == null) { converView = inflater.inflate(getLayoutResource(row, column), parent, false); } setText(converView, getCellString(row, column)); converView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (row == -1) { // clicked on header row cell for(int col=0; col<=getColumnCount(); col++){ if (col == column+1) { if (getColOrder(col) == 0 || getColOrder(col) == 2) { setText(v, getCellString(row, column) + " β"); // reset selected column header to ASC order setColOrder(col, 1); } else { setText(v, getCellString(row, column) + " β"); // reset selected column header to DESC order setColOrder(col, 2); } } else { setColOrder(col, 0); // reset all other column headers to 0 (not ordered) // TODO: // here we need to change the text of all other header cells, using their view ids } } } } }); return converView; }