Everyone;
I'm just learned to program Android with Eclipse, and here I have the simple program where I can enter the value from EditText element and print it in to the table, which is programmatically generated with the code below.
When the user clicks the Edit Button, I want to retrieve the value in Col1Txt(TextView) of the same row, and pass it to a variable.
I read a lot of samples in the online, but still not clear for me how to do this. Can anyone help me to complete this program?
Thanks.
public void Table_AddItem(Context srcpage,final TableLayout TargetTable, String StrCol1) {
// Creation row
final TableRow tableRow = new TableRow(srcpage);
tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
// Creation textView
final TextView Col1Txt = new TextView(srcpage);
Col1Txt.setText(StrCol1);
Col1Txt.setBackgroundResource(R.drawable.cellborder);
Col1Txt.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
// Edit button
final Button EditCmd = new Button(srcpage);
EditCmd.setText("Edit");
EditCmd.setBackgroundResource(R.drawable.cellborder);
EditCmd.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
EditCmd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Add the Code Here
}
});
tableRow.addView(Col1Txt);
tableRow.addView(EditCmd);
TargetTable.addView(tableRow);
}
尝试这种方式从TextView
获取String
Col1Txt.getText().toString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.