小编YaW*_*YaW的帖子

关闭自定义对话框?

我正在尝试创建一个自定义对话框以在此对话框中显示视图.这是Builder代码:

//Getting the layout
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog_simple,
                               (ViewGroup) findViewById(R.id.rlDialogSimple));

//Change Text and on click
TextView tvDialogSimple = (TextView) layout.findViewById(R.id.tvDialogSimple);
tvDialogSimple.setText(R.string.avisoComprobar);
Button btDialogSimple = (Button) layout.findViewById(R.id.btDialogSimple);
btDialogSimple.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        //Do some stuff

        //Here i want to close the dialog
    }
});

AlertDialog.Builder builder = new AlertDialog.Builder(AcPanelEditor.this);
builder.setView(layout);
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud)

所以,我想解雇btDialogSimple的onClick中的对话框.我怎么能这样做?我不知道如何从onclicklistener中调用dismiss方法.

我的按钮有自定义布局,所以我不想制作builder.setPositiveButton.

有任何想法吗?

android dialog

9
推荐指数
2
解决办法
1万
查看次数

如何取消待定的wait_for

假设命令与此类似:

@bot.command()
async def test(ctx):
    def check(r, u):
        return u == ctx.message.author and r.message.channel == ctx.message.channel and str(r.emoji) == '?'

    await ctx.send("React to this with ?")
    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=300.0, check=check)
    except asyncio.TimeoutError:
        await ctx.send('Timeout')
    else:
        await ctx.send('Cool, thanks!')
Run Code Online (Sandbox Code Playgroud)

wait_for如果用户在实际对消息作出反应之前多次发送相同的命令,有什么办法可以取消?因此,机器人停止等待先前发送的消息的反应,而仅等待最后一条消息。

python coroutine discord discord.py

6
推荐指数
1
解决办法
65
查看次数

如何保持用户登录的会话?

我有一个需要用户注册的应用程序.我已经在我的服务器中将应用程序连接到PHP以执行注册/登录的逻辑,因此,这根本不是问题.

但是,我想在本地保留用户的会话,因此用户无需每次运行应用程序时再次登录.

所以,我想要这样的东西:

  • 第一次用户,他打开应用程序,注册并登录.
  • 用应用程序做一些事情并关闭它.
  • 再次打开应用程序,用户被识别,因此无需再次登录.

我只需要存储一个ID和一个用户名(两者都是在登录php方法中从DB中获取的).什么是最好的方法?

我考虑过做一个自定义首选项,将数据存储在文件甚至是本地数据库(sqlite)中.有什么建议?

java session android

3
推荐指数
1
解决办法
5445
查看次数

Widget + TaskKiller中的PendingIntent

我开发了一个应用程序(称为即时按钮),该应用程序具有小部件功能.此小部件使用PendingIntent作为小部件的onClick.

我的PendingIntent代码是这样的:

    Intent active = new Intent(context, InstantWidget.class);
    active.setAction(String.valueOf(appWidgetId));
    active.putExtra("blabla", blabla); //Some data

    PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);

    actionPendingIntent.cancel();
    actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);

    remoteViews.setOnClickPendingIntent(R.id.button, actionPendingIntent);
Run Code Online (Sandbox Code Playgroud)

onReceive获取意图并使用MediaPlayer类做一些重现声音的东西.

我有一些用户的报告说,小部件在一段时间后停止工作,我发现的一些研究是因为任务杀手.看来,当您在TaskKiller中杀死应用程序时,PendingIntent将从内存中删除,因此当您单击该小部件时,它不知道该怎么做.

这有什么解决方案吗?我的代码是错的还是某些东西,或者它是PendingIntent的默认行为?有什么我可以用来避免TaskKiller阻止我的小部件工作?

问候.

android widget android-widget android-pendingintent

1
推荐指数
1
解决办法
1307
查看次数