Reputation: 1307
How to search rows which are dynamically created in table layout of android? I'm having a table layout which contains name and code as columns, how do i search those rows for particular name/code?
I'm trying to add tag in this way:
TextView empFirstName = null;
int i,j;
for (i=0; i<employees.size();i++){
final Employee employee = (Employee) employees.get(i);
int count = 0;
TableRow empData = new TableRow(this);
empData.setId(300+count);
empData.setClickable(true);
/*empData.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT ));*/
//tr.setClickable(true);
final TextView empCode = new TextView(this);
empCode.setId(300+count);
empCode.setText(employee.getCode());
empCode.setTextSize(16);
empCode.setPadding(2,2, 2, 2);
empCode.setLayoutParams(new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 2 ));
empData.addView(empCode);
final TextView empName = new TextView(this);
empName.setId(300+count);
empName.setText(employee.getCallName());
empName.setTextSize(16);
empName.setPadding(2, 2, 2, 2);
empName.setLayoutParams(new TableRow.LayoutParams( 0, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 4 ));
empData.addView(empName);
empFirstName = new TextView(this);
empFirstName.setId(007);
empFirstName.setText(employee.getFirstName());
empFirstName.setTag(i);
}
I'm trying to use setTag(), how do i retrieve value of text using getTag()}
Upvotes: 2
Views: 2174
Reputation: 8091
so from your i comment i think you want to create a list which hold some details. Instead of going for TableView and rows .You can use list view
Go through this Android developer site documentation .It will provide you many inbuilt features for getting row details and it's contents
Here is some tutorials :Tutorial 1
Tutorial 2 and Tutorial 3
These tutorial will help you to create simple list-view
First Get basic idea .Also get a picture about Adapter view
Later on you can customize the list view using custom adapter classes : See this
Hope this will help you
Upvotes: 1