如何实现不同活动的对话框?
我想在不同的活动中显示相同的对话框。我尝试制作一个BaseActivitiy
。这些活动扩展了我的基本活动。到目前为止,这是有效的,但现在我想更新当对话框关闭时显示对话框的活动。在我的例子中,更新意味着用 SQLite 数据库中的数据填充列表视图。
我还尝试检索类名以使用这些活动的更新方法。但是不可能将更新方法更改为静态,因为非静态 SQL 方法...
您有什么想法吗?
活动:
public class MyActivity extends Dialogs {
...
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int idx = info.position;
switch (item.getItemId()) {
case CONTEXTMENU_ID:
showMyDialog(this,DIALOG_ID);
break;
}
return true;
}
public void update() {
...
}
}
DialogsClass
public class Dialogs extends Activity {
@Override
protected Dialog onCreateDialog(int id) {
...
}
...
//Called on Dialog-Butten press
private void ReloadActivity(){
if(DialogCalledByClass.contains("MyActivity")) {
MyActivity.update();// It doesn't worke because non-static....
}
else if(DialogCalledByClass.contains("MyActivity2")) {
}
}
public void showMyDialog(Context ctx,int id) {
showDialog(id);
DialogCalledByClass =ctx.getClass().toString();
}
}
这就是我尝试过的......
I want to show the same dialog in different activities. I tried to make a BaseActivitiy
. The Activities extends my BaseActivity. That worked so far, but now I want to update the Activity which shows the dialog when the dialog is closed. Update means in my case to fill a listview with data from a SQLite database.
I also tried to retrieve the classname to use the update method of those activities. But it is not possible to change the update method to static, because of the non-static SQL methods...
Do you have any idea?
Activity:
public class MyActivity extends Dialogs {
...
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int idx = info.position;
switch (item.getItemId()) {
case CONTEXTMENU_ID:
showMyDialog(this,DIALOG_ID);
break;
}
return true;
}
public void update() {
...
}
}
DialogsClass
public class Dialogs extends Activity {
@Override
protected Dialog onCreateDialog(int id) {
...
}
...
//Called on Dialog-Butten press
private void ReloadActivity(){
if(DialogCalledByClass.contains("MyActivity")) {
MyActivity.update();// It doesn't worke because non-static....
}
else if(DialogCalledByClass.contains("MyActivity2")) {
}
}
public void showMyDialog(Context ctx,int id) {
showDialog(id);
DialogCalledByClass =ctx.getClass().toString();
}
}
That's what I have tried...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如...您可以创建自己的对话框,而不是创建 BaseActivity:
我不知道我是否理解了您的问题,但这是一个想法。我希望它对你有帮助。
For example... Instead of create a BaseActivity you could create your own Dialog:
I don't know if I've understood your question, but it's an idea. I hope it help you.
我找到了一个解决方案。谢谢你大卫!!抱歉,我无法投票,因为声誉较低......
I found a Solution. Thanks to you David!! Sry I couldn't vote up because to less reputation...