我想动态创建一个按钮,但在为其设置ID时遇到了问题。我尝试在其中放置一个整数值,但不断收到错误消息,提示“ExpectedResourceofTypeID.”问题是我不想在我的XML文件中创建此按钮,但我需要一个使用ID跟踪它的方法。请帮忙。ButtonchangeButton=newButton(getApplicationContext());changeButton.setText("Change");changeButton.setId(1);//KeepGettinganerrorhere 最佳答案 在您的res/valu