Android 按钮问题
我在 mainActivity 上创建了一个按钮。单击后,用户将进入第二个视图。 由于某种原因,在任何地方都看不到按钮并且没有错误?我已经在 xml.file 中定义了布局并在 java.file 中引用了它。奇怪的是没有明显的语法错误,也没有任何地方可以看到按钮。
下面是 java 代码段:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);
mDbHelper = new RemindersDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
setContentView(R.layout.reminder_list);
final Button button = (Button) findViewById(R.id.insertion);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Performs action on click
createReminder();
}
});
}
这是 .xml 文件
http: //imageshack.us/photo/my-images/171/xml.png/
有人有什么想法吗?
非常感谢。
I've created a button on the mainActivity. Once clicked, it takes a user to a second view.
For some reason, there's no button to be seen anywhere and there's no errors? I have defined the layout in the xml.file and referenced it in the java.file. It's just strange that there's no obvious syntax errors and there's no button to be seen anywhere.
Below is the segment of the java code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);
mDbHelper = new RemindersDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
setContentView(R.layout.reminder_list);
final Button button = (Button) findViewById(R.id.insertion);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Performs action on click
createReminder();
}
});
}
This is the .xml file
http://imageshack.us/photo/my-images/171/xml.png/
Does anyone have any ideas?
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在你的布局内部。
您将 ListView 设置为 android:layout_height="fill_parent" ,以便 listView 将消耗所有布局高度,并且您的按钮将不会出现。
如果您需要 Activity 底部的按钮,请尝试使用wrap_content 或使用RelativeLayout。
The problem is inside your layout.
You set the ListView with android:layout_height="fill_parent" so that listView will consume all the layout height and your button will not appear.
Try using wrap_content or using RelativeLayout if you need the button at the bottom of your Activity.