如何搜索在android的表格布局中动态创建的行?我有一个表格布局,其中包含名称和代码作为列,我如何在这些行中搜索特定的名称/代码?
我正在尝试以这种方式添加标签:
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);
}
我正在尝试以这种方式检索名称:
for(j=0;j<=i;j++){
TextView names = (TextView) empFirstName.getTag(j);
System.out.println("Name is "+names.getText());
}
但它抛出空指针异常!