Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View or Fragment library to compose UI for common data types

Problem

I need to let the user enter an email, pick a date, edit a webpage, choose an image etc - there are a number of common presentation tasks that are not directly subserved by the Android SDK widget library and so I thought there may be a dedicated repository or framework available that specializes in such UI concerns.

[ While Android provides widgets that can be turned into specific editors for email, for instance, the question here regards finding a library of ready-made components that specifically target such common data types i.e. UI elements which are specifically geared towards presenting such data, out-of-the-box, as well as providing validation. ]

Existing Sources?

So I searched the web with a combination of terms like Android, widget, library, view, toolkit, fragment, repository, but came up with false positives only.

Could you refer me to any collective efforts that provide a list of classes / XML layouts implementing common data-specific input / editing / configuration elements?

So I could do something like this in ActivityA1, ActivityA3, ActivityB1, ActivityN9:

  • new EmailEditText()
  • new UrlTextView()
  • new IPView() ...

Matching Data to Views?

What I'm really looking for is a set of widgets that would be resolved according to the data that needs to be presented, perhaps similarly to implicit intent resolution ?

So from my domain model I would provide some data with a specific data type, which should be displayed somehow appropriately. But I do not explicitly set what View will present this data, instead there is a matcher inbetween that filters a list of available specific-purpose views and selects the most appropriate one for the given data type.

Anything like that out there already?

like image 467
Cel Avatar asked Apr 25 '12 11:04

Cel


People also ask

Should I use fragments with Compose?

You don't need Fragments with Compose. You can navigate to another screen without needing a Fragment or an Activity: class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.

Does jetpack compose use view?

Jetpack Compose is designed to work with the established View-based UI approach. If you're building a new app, the best option might be to implement your entire UI with Compose. But if you're modifying an existing app, you might not want to fully migrate your app all at once.

Is jetpack compose better than XML?

Compose allows you to do more with less code compared to XML. Compose is Intuitive. This means that you just need to tell Compose what you want to show the user. Compose is compatible with all your existing code: you can call Compose code from Views and Views from Compose.


1 Answers

Unfortunately, Android doesn't have exactly what you want, but don't worry - there are definitely things to make your life easier.

For example, you can set the inputType on an EditText to change what the keyboard looks like (eg. for e-mail you have "@" and ".com" buttons, for a phone number you have numbers) and use InputFilter to control data entry.

You can even use EditText.setTransformationMethod() to change the way the data is presented (like adding spaces in a phone number).

And if you want to pick an image, you can send off an intent to request it: http://android-er.blogspot.se/2011/02/select-image-using-android-build-in.html

It shouldn't be too hard building your own set of widgets that does just what you want by combining these approaches.

Update: There is now a library available that makes form validation easier: https://github.com/vekexasia/android-form-edittext

like image 62
Marcus Forsell Stahre Avatar answered Sep 23 '22 12:09

Marcus Forsell Stahre