Get a list of text fields available at runtime?

I use an android library called Proteus that inflates layouts at runtime using the JSON file that we are sitting on our server. This library allows you to bind data, but my question is how can I get data from these fields when using my applications? I cannot refer to any of the layout identifiers because they do not exist at compile time. Is there a way to ignore an error in an instruction when (R.id.input) does not actually exist before execution ?:

View view = inflater.infalte(R.layout.fragment_form, container, false);
TextView textView = (TextView)view.findViewById(R.id.input);

Or perhaps programmatically get a list of all available unique identifiers at runtime? Any information would be helpful. Thank.

+4
source share
1 answer

proteus generates display identifiers at runtime, unlike identifiers intgenerated at compile time for Android XML layouts. Unlike Android, view identifiers created by proteus are based on String, and R.id.<something>will not work.

Proteus provides utilities for finding the Stringid type .

Markup:

{
  "type": "TextView",
  "id": "myId"
}

Java:

View view = proteusView.getViewManager().findViewById("myId"); // can be null

The returned view may also be ProteusView

See the wiki for more details .

Wikis are a bit outdated, the answer is higher for 5.0.0-rc11release and higher. Wiki should be updated soon.

+2
source

Source: https://habr.com/ru/post/1667991/


All Articles