我正在尝试创建一个自定义对话框以在此对话框中显示视图.这是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.
有任何想法吗?
假设命令与此类似:
@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如果用户在实际对消息作出反应之前多次发送相同的命令,有什么办法可以取消?因此,机器人停止等待先前发送的消息的反应,而仅等待最后一条消息。
我有一个需要用户注册的应用程序.我已经在我的服务器中将应用程序连接到PHP以执行注册/登录的逻辑,因此,这根本不是问题.
但是,我想在本地保留用户的会话,因此用户无需每次运行应用程序时再次登录.
所以,我想要这样的东西:
我只需要存储一个ID和一个用户名(两者都是在登录php方法中从DB中获取的).什么是最好的方法?
我考虑过做一个自定义首选项,将数据存储在文件甚至是本地数据库(sqlite)中.有什么建议?
我开发了一个应用程序(称为即时按钮),该应用程序具有小部件功能.此小部件使用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阻止我的小部件工作?
问候.