解说社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1640|回复: 10

[原创] 分享本人闲来无事定义的dialog函数(利用table)

[复制链接]
发表于 2020-9-3 20:32:52 来自手机 | 显示全部楼层 |阅读模式
function 对话框(表)
if type(表)=="table" then
if 表.标题 then
  else
  表.标题=""
  end
if 表.消息 then
  else
  表.消息=""
  end
if 表.积极 then
  else
  表.积极=""
  end
if 表.积极事件 then
  else
  表.积极事件=""
  end
if 表.消极 then
  else
  表.消极=""
  end
if 表.消极事件 then
  else
  表.消极事件=""
  end
if 表.中立 then
  else
  表.中立=""
  end
if 表.中立事件 then
  else
  表.中立事件=""
  end

return AlertDialog.Builder(activity)
.setTitle(表.标题)
.setMessage(表.消息)
.setNegativeButton(表.积极,{onClick=function()
loadstring(表.积极事件)()
    end})
.setPositiveButton(表.消极,{onClick=function()
loadstring(表.消极事件)()
    end})
.setNeutralButton(表.中立,{onClick=function()
loadstring(表.中立事件)()
    end})
.show()
end
--例如
对话框{标题="你好",消息="我好",积极="大家好"}
--注意:如无需部分参数可省略。例如上面的例子中就省略了消极,中立按钮的事件和积极按钮的事件。



  来自解说社区客户端
回复

使用道具 举报

 楼主| 发表于 2020-9-3 20:38:05 来自手机 | 显示全部楼层
那什么,还有个end忘记加了,各位自己记得补充哈。



  来自解说社区客户端
回复

使用道具 举报

发表于 2020-9-3 20:52:11 来自手机 | 显示全部楼层
感谢楼主的分享。



  来自解说社区客户端
回复

使用道具 举报

发表于 2020-9-3 21:00:08 来自手机 | 显示全部楼层
回复 楼主问题真难写

巧妙的思路



  来自解说社区客户端
回复

使用道具 举报

发表于 2020-9-4 12:00:32 来自手机 | 显示全部楼层
--问一下这样为什么会报错
function 对话框(表)
if type(表)=="table" then
if 表.标题 then
else
表.标题=""
end
if 表.消息 then
else
表.消息=""
end
if 表.积极 then
else
表.积极=""
end
if 表.积极事件 then
else
表.积极事件=""
end
if 表.消极 then
else
表.消极=""
end
if 表.消极事件 then
else
表.消极事件=""
end
if 表.中立 then
else
表.中立=""
end
if 表.中立事件 then
else
表.中立事件=""
end

return AlertDialog.Builder(activity)
.setTitle(表.标题)
.setMessage(表.消息)
.setNegativeButton(表.积极,{onClick=function()
loadstring(表.积极事件)()
end})
.setPositiveButton(表.消极,{onClick=function()
loadstring(表.消极事件)()
    end})
.setNeutralButton(表.中立,{onClick=function()
loadstring(表.中立事件)()
end})
.show()
end
end
--例如
print(对话框{标题="你好",消息="我好",积极="大家好"})
--注意:如无需部分参数可省略。例如上面的例子中就省略了消极,中立按钮的事件和积极按钮的事件。



  来自解说社区客户端
回复

使用道具 举报

发表于 2020-9-4 13:02:47 来自手机 | 显示全部楼层
回复 5楼 杨培欢

首先 第44行的end旁边有错误符号。
在着你加print做什么。
另外使用Dialog需要导入。
require "import",
其次,如果是在插件里运行,还需要把
AlertDialog.Builder(activity)
修改为
LuaDialog()



  来自解说社区客户端
回复

使用道具 举报

 楼主| 发表于 2020-9-4 13:04:10 来自手机 | 显示全部楼层
回复 5楼 杨培欢

报错什么



  来自解说社区客户端
回复

使用道具 举报

发表于 2020-9-4 13:04:42 来自手机 | 显示全部楼层
import "com.androlua.LuaDialog"



  来自解说社区客户端
回复

使用道具 举报

 楼主| 发表于 2020-9-4 13:07:29 来自手机 | 显示全部楼层
回复 6楼 shengjie

一般来讲,print貌似可以支持所有的数据类型,不过貌似也没必要。打印出来的没啥用。



  来自解说社区客户端
回复

使用道具 举报

发表于 2020-9-4 14:40:46 来自手机 | 显示全部楼层




  来自解说社区客户端
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|解说社区

GMT+8, 2024-4-27 06:30 , Processed in 0.048219 second(s), 13 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表