add buttons array in adapter using grid view
You need to extend the ArrayAdapter class and override getView() to return the type of view you want for each item, a button in this case. You can then try or use the type with no type parameter.
https://developer.android.com/guide/topics/ui/declaring-layout.html#AdapterViews
how to put dynamic arraylist button in gridlayout or gridview
Instead of using GridLayout
, use RecyclerView
with GridLayoutManager
and a span size of 2. There are number of benefits using RecyclerView
over GridLayout
if you want to populate your view according to an ArrayList
.
How to add buttons to grid view?- Android
Hi Check the below code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="10dp"
android:text="Back" />
<GridView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
<Button
android:id="@+id/btnCapturePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:text="Camera" />
</LinearLayout>
</LinearLayout>
dynamically add array of buttons and reference those buttons by id in android
In code why don't you just declare a class level variable? Another common technique is to save references as tags or save whole bunch of references in the holder object and save that as a tag
Add new Array of numbers to Gridview after using OnclickItemListener
You could hold a reference to the list:
numbersArrayList = randomArray(arrayNumbers);
final ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,
android.R.layout.simple_list_item_1, numbersArrayList);
And then without changing the reference you can update the items in your OnItemClickListener
:
numbersArrayList.clear();
List<Integer> newList = randomArray(arrayNumbers);
Collections.shuffle(newList);
numbersArrayList.addAll(newList);
adapter.notifyDataSetChanged();
Android UI - add buttons dynamically to Gridview
1) How to create a list view inside a main view, only using a half of the screen.
This is done by the weight attribute. A rough example for your sketch: The top wrapper (edittexts and buttons) has a weight of .45, the listview has a weight of .45 and the footer has a weight of .1. You can specify the weight-sum in the surrounding view; but default should be 1.
2) How to populate list view in grid manner (a row of two columns will repeat itself)
Well, with the GridView (the adapter API is the same) (:
Related Topics
How to Include a Library Module Dependency in an Android Studio Project
Scoping States in Jetpack Compose
How to Add PDFbox to an Android Project or Suggest Alternative
How to Implement Pagination in Android Listview
Android Accessibility Service Detect Notification
Delete File from Internal Storage
How to Add .So Files to an Android Library Project Using Gradle 0.7+
Install App via Usb: the Device Is Temporarily Restricted
Updated Sdk Version, Getting Classnotfoundexception: Android.Support.V4.View.Viewpager
How to Check If Running on UI Thread in Android
How to Use Selector to Tint Imageview
Triggering Event When Button Is Pressed Down in Android
Android - Detect End of Long Press
Floatingactionbutton Doesn't Hide
Start New Activity and Finish Current One in Android