新手:Android 按钮
我有两个按钮 b1 和 b2 。如果按下按钮 b1 则执行查询 q1,否则如果按下按钮 b2 则执行另一个查询 q2。
if(b1_click)
{
mCursor=//query
}
else if(b2_click)
{
mCursor=//query
}
请告诉我如何实现这个。如何实现 b1_click 方法或任何告诉按钮被按下的内置方法。我尝试过,
Cursor c;
c=//querys
if(b1.isPressed())
{
next.setOnClickListener
(
new View.OnClickListener()
{
@Override public void onClick(View v) {
c=db.getData1(); (getData1 method return cursor)
}
}
);
}
tv.append(c.getString(column_number) (tv=TextView)
"Same as above for b2"
它是说光标(c)应该是最终的 帮助?
I have two button b1 and b2 .If button b1 is pressed then perform a query q1 else if button b2 is pressed then perform an another query q2.
if(b1_click)
{
mCursor=//query
}
else if(b2_click)
{
mCursor=//query
}
Please tell me how can i implement this.How to implement b1_click method or any inbuilt method which tell that button is pressed.I tried
Cursor c;
c=//querys
if(b1.isPressed())
{
next.setOnClickListener
(
new View.OnClickListener()
{
@Override public void onClick(View v) {
c=db.getData1(); (getData1 method return cursor)
}
}
);
}
tv.append(c.getString(column_number) (tv=TextView)
"Same as above for b2"
It is saying that cursor (c) should be final
Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我建议您阅读一些教程Hello Android,您可以另请遵循常见任务以及如何在 Android 中执行这些任务中的代码和示例。
如果你仔细阅读这篇文章,你会知道这很简单,就像这样:
First of all I would recommend going through some tutorials Hello Android and you could also follow the code and samples in Common Tasks and How to do them in Android.
If you would read this carefully you would know that is very simple, something like this:
尝试将 OnClickListeners 创建为私有类:
然后设置 onClick-listeners:
如果您需要 OnClickListeners 能够使用光标,则只需在 OnClickListeners 的父类中将其声明为私有字段即可。
Try creating your OnClickListeners as private classes:
Then you set the onClick-listeners:
If you need the OnClickListeners to be able to use the cursor, you just need to declare it as a private field in the parent class of the OnClickListeners.