Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

启动预览运行界面时,界面view的传值(内存)方式 #3

Open
2439905184 opened this issue Jan 5, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@2439905184
Copy link
Owner

主要思路,通过intent.putExtra(String key,String value);实现内存中传值
关于value使用map变量和ArrayList和json(Gson库)处理
创建布局界面里使用

map.put("text","按钮");
map.put("width",-2);
intent.putExtras("layout"),newGson().toJson(ArrayList<map> views))
intent.setClass(Context,sub.class)
startActivity(intent)

接收端

layout = new Gson().fromJson(getIntent().getStringExtra("layout")
//遍历所有ArrayList<map> 就是获取每一个map元素
//再从每一个map元素中取值(根据key)
//然后动态创建view,动态设置属性,最后添加到布局中去
@2439905184
Copy link
Owner Author

ArrayList相当于大数组(存储每一个view对象的数据),map对象可以存放多个key(作为一个view对象(自身)的数据容器存储)。

@2439905184 2439905184 added the enhancement New feature or request label Jan 5, 2022
@2439905184 2439905184 pinned this issue Jan 5, 2022
@2439905184 2439905184 self-assigned this Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant