Jul 16, 2022 19:03
Yeah, I would have assumed that too
Jul 16, 2022 18:56
FWIW, the text in the docs is actually correct, it's just the example code that is wrong

"The generated binding class is called ResultProfileBinding. This class has two fields: a TextView called name and a Button called button."
Jul 16, 2022 18:30
USA (Seattle)
Jul 16, 2022 18:15
Yeah, just have to wait at this point
Jul 16, 2022 18:14
reading answers in the SO android channel is sometimes helpful, I've learned new things that way
Jul 16, 2022 18:13
but even that is like 3 years since it was updated...
Jul 16, 2022 18:13
e.g. here's their sample RecyclerView demo app

https://github.com/android/views-widgets-samples/tree/main/RecyclerView
Jul 16, 2022 18:12
3 votes I think
Jul 16, 2022 18:12
If you want example code, the android sample apps (developer.android.com/samples) are a bit more up-to-date
Jul 16, 2022 18:12
can't add answers on closed questions
Jul 16, 2022 18:11
I can post an answer once it is re-opened
Jul 16, 2022 18:11
Those are just as likely to be out of date
Jul 16, 2022 18:08
but for anything more complicated you'd have to make it yourself
Jul 16, 2022 18:08
If the list is really simple (e.g. just show some text) android has some pre-made layouts you can use (don't remember the exact code but it's something like android.R.layout.single_item_list)
Jul 16, 2022 18:07
so you're always going to need separate layouts when making this list-type containers
Jul 16, 2022 18:07
The activity itself also needs a layout to display the List/Grid/Recycler view in
Jul 16, 2022 18:07
No, that would not work. For things like ListView, GridView, RecyclerView, you need a separate layout for it to use for its items
Jul 16, 2022 18:06
you mean putting your "country" and "currency" TextViews in the main activity XML?
Jul 16, 2022 18:06
I'm not sure I follow
Jul 16, 2022 18:02
I made an update to the question - feel free to edit it further if you feel I've mis-represented your question.
Jul 16, 2022 18:00
Yes, the main activity plus the layout for each grid cell
Jul 16, 2022 17:58
yeah, like getName it is now just "binding.gridView"
Jul 16, 2022 17:56
If you want I can help edit the question.
Jul 16, 2022 17:54
I'll add an answer, and hopefully it will help someone else avoid the same trouble you ran into
Jul 16, 2022 17:54
I suggest you update your question to reflect that (you can even remove the adapter and just show that "getGridView()" doesn't work)
Jul 16, 2022 17:51
note that there are two bindings - you have to inflate the main activity binding at the top level, and the row binding inside the adapter
Jul 16, 2022 17:51
Here is a working onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

ArrayAdapter<Country> cheeseAdapter =
new ArrayAdapter<Country>(this, 0, countries) {

@Override
public View getView(int position,
View convertView,
ViewGroup parent) {

CountryListBinding rowBinding;

if(convertView == null) {
rowBinding = CountryListBinding.inflate(getLayoutInflater(), parent, false);
Jul 16, 2022 17:50
the docs here (developer.android.com/topic/libraries/view-binding) show getName() like you were doing. Typing "binding." in Android Studio will show you a context hint for what options are available
Jul 16, 2022 17:48
but once I do, it would be a good idea for you to edit your question to reflect what you pasted above - the fact that getName() was removed is not in the official docs
Jul 16, 2022 17:47
your code is pretty close, I'll post the update here
Jul 16, 2022 17:47
I just pulled your code, turns out the documentation for view binding with java is out of date - you now use binding.name.setText not binding.getName().setText.
Jul 16, 2022 17:31
What happens? Cannot resolve "getName" or some other error?
Jul 16, 2022 15:24
yeah, the link should be in the comments on your original question
Jul 16, 2022 15:22
apparently no...
Jul 16, 2022 15:22
```
test - does code formatting work in chat?
```
Jul 16, 2022 15:21
so in the Activity onCreate, I inflate the Activity binding, create the adapter, and set it on the RecyclerView

In the Adapter in `onCreateViewHolder` I inflate the binding for the row layout (a separate XML)
Jul 16, 2022 15:20
this is all Kotlin
Jul 16, 2022 15:20
The adapter (in a separate file to keep things clean)

class CatFactAdapter : ListAdapter<CatFact, CatFactAdapter.ViewHolder>(DIFF_CALLBACK) {

class ViewHolder(val binding: CatFactRowBinding) : RecyclerView.ViewHolder(binding.root)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = CatFactRowBinding.inflate(
LayoutInflater.from(parent.context), parent, false
)
return ViewHolder(binding)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
Jul 16, 2022 15:20
The activity

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCatsBinding.inflate(layoutInflater)
setContentView(binding.root)

val adapter = CatFactAdapter()
binding.factList.adapter = adapter
}
Jul 16, 2022 15:19
I made a simple test app for learning some things that does this - I can share some example code here
Jul 16, 2022 15:18
ListView is an older capability that doesn't have as many features as RecyclerView (e.g. can't show a grid) but otherwise is similar - you would make an XML to show for each row and an adapter to control how those rows data gets set
Jul 16, 2022 15:17
What do you mean with ListView?
Jul 16, 2022 15:17
Here is another tutorial raywenderlich.com/…
Jul 16, 2022 15:15
and then you would make a separate xml file to define the layout to use in each "grid cell"
Jul 16, 2022 15:15
your main activity XML would just have a single <RecyclerView that takes up the whole screen
Jul 16, 2022 15:14
but for your main question, try making a RecyclerView like at the guide I posted - a RecyclerView can be either a linear layout or a grid layout
Jul 16, 2022 15:14
and Kotlin and Java are interoperable, so you can still use Java libraries etc
Jul 16, 2022 15:13
I migrated all my apps from Java to Kotlin - it is a lot "friendlier" of a language IMO
Jul 16, 2022 15:13
I would say Kotlin is the preferred way these days
Jul 16, 2022 15:12
You can use a RecyclerView to display a grid of data like you are looking to do