2011-08-25 61 views
1

這裏是我的代碼動態添加行到TableLayout。每一行都有兩個Textviews。將選擇功能添加到表格行

final TableLayout tl = (TableLayout)findViewById(R.id.tbl); 
TableRow tr = new TableRow(this);    

TextView tv1 = new TextView(this); 
TextView tv2 = new TextView(this); 

createView(tr, tv1, "hello1"); 
createView(tr, tv2, "hello2"); 

tl.addView(tr);    


public void createView(TableRow tr, TextView t, String viewdata) { 

t.setText(viewdata); 
t.setTextColor(Color.DKGRAY); 
t.setBackgroundColor(Color.WHITE); 
tr.addView(t); // add TextView to row. 
} 

如何將選擇功能設置爲該行?點擊該行後,我必須開始一個新的活動。請幫幫我。

回答

2
tr.setClickable(true); 
    tr.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      Intent intent = new Intent(CurrentActivity.this, NewActivityToBeLaunched.class); 
      startActivity(intent); 
     } 
    }); 
+0

謝謝。我的問題解決了。 – Santhosh