I need to create a ListView or TableLayout that each row consists of 3 columns and 3 buttons, something similar to that:

but the screen will not only contains this control will contains textfields and other layouts , I need a grid to take the shape like as the following (for example ).
Any idea on how to achieve that and how to handle Button clicks on it?
As I am new to Android I don’t know how to create that.

A
ListViewis used mainly for mutable data. If you have some sort of data that can be displayed the same way everytime and it can grow/be deleted, then a ListView is a good option.On the other way if you have static data, static Layouts (like TableLayout, LinearLayout, etc) are a good option. It all depends on what data you have and how you want to use it.
I hope you don’t want to to do the same columns you have on that screenshot because you don’t have that space on a smartphone.
Let’s assume you want 3 columns, and that data is mutable.
You can use a costum ListView with a
LinearLayoutin the root with theandroid:orientation="horizontal. Then each element on you insert you need to uselayout_weight="1"with theandroid:layout_width="0dp". This combination guarantees that each element on yourListViewrow will have the same width, so it is kinda optional.Your costum list row should seem something like this:
To handle the button click you need to do a
setOnClickListenerin the Button when you get it in thegetViewmethod inside the adapter on your costum ListView.Then you probly will have problems clicking the button and the ListView. A common way to solve that is to put the button as
android:focusable="false"at the xml where you declare it. But one thing at a time 😉EDIT (because of the comment: Adding a checkbox that disable/enables a button):
If you want a checkbox to disable/enable buttons you need to do some work on your
getViewin the adapter of your costum ListView.You need to:
CheckBox myCheckBox = (CheckBox) inflater.findViewById(R.id.checkboxid)where the inflater is the one you defined in the getView and the checkboxid is the id you defined at your xml row.myCheckBox.setTag(button)where the button is the button you want to enable/disable and you can get him the same way you got the myCheckBoxsetOnCheckedChangeListeneron your checkbox where you change the visibility of your button depending on the state of the checkbox.The last bullet should sound something like this: