我創建內動態選擇tablerow的一個Tablelayout許多TableRows,例如:一個TableLayout動態
for(int i = 0; i<cont; i++)
{
id[i] = customers[i].CustomerNumber;
//Create a new row to be added.
tr = new TableRow(this);
//Create text views to be added to the row.
tv = new TextView(this);
//Put the data into the text view by passing it to a user defined function createView()
createView(tr, tv, id[i].ToString());
//Add the new row to our tableLayout tl
tl.AddView(tr);
}
這是CreateView的代碼:
private void createView(TableRow tr, TextView t, String viewdata) {
t.SetText(viewdata, TextView.BufferType.Editable);
//adjust the porperties of the textView
//t.SetLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
//You have to use Android.Graphics.Color not System.ConsoleColor;
t.SetTextColor(Color.Blue);
t.SetBackgroundColor(Color.Cyan);
t.SetPadding(5, 0, 0, 0);
tr.SetPadding(0, 1, 0, 1);
tr.SetBackgroundColor(Color.Black);
tr.AddView(t); // add TextView to row.
}
我的問題是,我希望從包含單行內所有內容的TableLayout中進行選擇,以便能夠選擇並響應點擊事件,以便將其用於其他目的。
如何我可以得到行的ID嗎? – arkmetal 2012-07-05 17:05:39
爲什麼你需要行的id? – 2012-07-05 17:16:15
看到我的編輯答案 – 2012-07-05 17:18:00