我创建了一个扩展类TextView
public class EmployeeTextView extends TextView {
private String employeeId;
private String employeeName;
public EmployeeTextView( Context context, String employeeId,
String employeeName ) {
super( context );
this.employeeId = employeeId;
this.employeeName = employeeName;
}
public String getEmployeeId( ) {
return employeeId;
}
public void setEmployeeId( String employeeId ) {
this.employeeId = employeeId;
}
public String getEmployeeName( ) {
return employeeName;
}
public void setEmployeeName( String employeeName ) {
this.employeeName = employeeName;
}
@Override
public CharSequence getText( ) {
return this.employeeId + " - " + this.employeeName;
}
}
我将如何在我的主要活动中实现这个类?我必须以EmployeeTextView
编程方式创建这些“”吗?或者有没有办法创建一个自定义小部件并通过 XML 添加它,然后调用我的 getter 和 setter?
我需要这个自定义 TextView 的原因是我需要单独获取employeeId 或employeeName。
谢谢