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()));
是说它不能从视图转换为字符串。
你想'显示为一个字符串或textView' – 2012-04-17 14:00:26
请告诉我们的main.xml文件和也粘贴完整的代码,这段代码有缺失大括号 – 2012-04-17 14:11:50