0
下面表格佈局是我的代碼動態添加錶行,`無法獲取動態添加的行的行ID在Android的
for (int j = 0; j < list.size(); j++) {
TableRow tableRow = new TableRow(getActivity());
table_layout.addView(tableRow);
tableRow.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
tableRow.setId(j);
tableRow.setClickable(true);
tableRow.setOnClickListener(tablerowOnClickListener);
TextView textView0 = new TextView(getActivity());
textView0.setLayoutParams(new TableRow.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
textView0.setText(currencySymbol.get(j));
textView0.setGravity(Gravity.CENTER_HORIZONTAL
| Gravity.CLIP_VERTICAL);
tableRow.addView(textView0);
TextView textView1 = new TextView(getActivity());
textView1.setLayoutParams(new TableRow.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
textView1.setGravity(Gravity.RIGHT);
tableRow.addView(textView1);
}
,這裏是onclicklistener
OnClickListener tablerowOnClickListener = new OnClickListener() {
public void onClick(View v) {
//GET TEXT HERE
//String currenttext = ((TextView)v).getText().toString());
Toast.makeText(getActivity(), "row selected" + View.getId , 30).show();
}
};
但是我不通過這種方法獲得行ID,我指的是this問題和this one also。
嘿嘿,謝謝BlackTiger,我應該嘗試這樣做。 – Sumit