int department;
Button search;
String display;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
department = 0;
search = (Button) findViewById(getResources().getIdentifier("btnSearch", "id", getPackageName()));
display = (String) findViewById(getResources().getIdentifier("tvDisplay", "id", getPackageName()));
search.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (department == 1)
{
display = "food";
}
我想要做的是让用户输入一个数字,点击一个按钮,它将在我底部的 textView 中显示一个部门名称。但是,我遇到了错误,我已经将它的几个部分转换为字符串而不是 textView。我如何修复输出的去向?
display = (String) findViewById(getResources().getIdentifier("tvDisplay", "id", getPackageName()));
说它不能从视图转换为字符串。