java我对一个显示器的问题有一个非常不切实际的询问
package walmart.namespace;
import 安卓.app.Activity;
import 安卓.os.Bundle;
import 安卓.view.View;
import 安卓.widget.Button;
导入安卓。小装置。编辑文本; 导入安卓。小装置。文本视图
public class WalmartActivity extends Activity {
/** Called when the activity is first created. */
EditText name;
Button search;
TextView display;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
name = (EditText)findViewById(R.id.etName);
search = (Button) findViewById(R.id.btnSearch);
display = (TextView) findViewById(R.id.tvdisplay);
name.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
name.setText("");
}
});
search.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (name.equals("Electronics")) {
display.setText ('5');
} else if (name.equals("candy")) {
display.setText ('1');
} else if (name.equals("Tobacco")) {
display.setText ("1");
}
}});
};}
无论我做什么,我的输出中都没有显示任何内容。我对JAVA非常、非常陌生,所以我似乎不知道为什么我的显示器上什么都没有显示
编辑将我的代码编辑为我当前拥有的代码。还是不行
# 1 楼答案
看看这些代码,问题可能在于如何初始化名称和搜索
更改代码:
为此:
另外,添加一个文本视图,将您的答案显示到
main.xml
文件中,给它一个id(比如说display)android:id="@+id/display"
,然后将其添加到您的活动中,以便您可以更改它:然后您可以通过以下方式进行更新:
因此,文件的开头应该如下所示:
下一步从以下位置更新
if
语句:致:
下面是一段代码示例:
人口活动。爪哇
缅因州2。xml