I made a subclass of button called Block for a minesweeper like game. I then made a 2d array of this class. Is there an easy way to display this array in a grid?
Thanks
You should use a GridView with a custom adapter. There is enough documentation available at
the Android developer website
Here is a tutorial for a custom adapter. The tutorial uses a ListView, but the adapter will also work with a GridView
Related
Is there a JavaFX equivalent to the Android SDK's listview where you can customize the items to have a specific layout using xml?
For instance in Android, if every item needs to have two text boxes for two separate properties, you can make a custom ArrayAdapter and populate the listview using that.
As far as I know, the ListView in FX isn't built for that.
Thanks in advance
I'm trying to make a android app with a scrollable list like this one...
When I made this app in iOS, I used a UICollectionView. What`s the best way to make this in android studios?
I tried using a list view, but I can't seem to customize it to my needs?
Any Ideas?
ListView was a great way to start and it is customizable to your needs.
However I would recommend to use RecyclerView which works almost on the same principle as ListView but it is a newer concept in Android. It handles the usage of the ViewHolder pattern for you which makes everything super easy.(With ListView, you would've had to implement your own ViewHolder pattern)
All you need to do is to have the RecyclerView in your activity/fragment as the view to hold your data. Then, the key component is to implement the RecyclerView's Adapter which will handle the inflation and setup of each list item.
Here is a really great and short tutorial to get you started with RecyclerView.
If you're done with that here is a bit more advanced video material on RecyclerView from Dave Smith explaining a lot of ways on how to understand and use RecyclerView in your apps.
A ListView fed by an ArrayAdapter of custom objects can do the job.
You might have a class that contains the text and the image of a single item.
Then you can create an ArrayList with items of that class, where you put in all the data.
This ArrayList can be used as dataset for a custom ArrayAdapter, which overrides the getView()-method.
The getView()-method must inflate the xml-layout for each item and attach the data from the ArrayList to the inflated view.
You might want to implement the Viewholder-pattern to achieve a good performance and avoid unnecessary inflations and getViewByID()-calls.
You can also use the new CardView, which can make it a lot easier, since it is made for the new material design in android 5, which looks similar to your item list.
I am creating a custom Spinner in Xamarin.Android with text and image. I've created the Spinner in Xamarin but don't know how to customise it.
For example how do I create rounded corners and with customised text and image?
Can anyone tell me how to achieve this? I was not able to upload the screen shot of what i have done so far since my reputation is low.
It is done exactly the same way as in Native Android development. You need to implement a custom Adapter to fill the Spinner with Views that live up to your requirement. Such an Adapter handles which View is shown when and at which position. It handles inflating these Views and populating them with the correct data.
As for styling the Spinner, it is done through the Styling system that Android provides. Which is not specific to how Xamarin.Android (or MonoDroid) does it.
You need to look into the documentation about Custom Adapters, read Creating Custom Row Layouts (in this case they are for ListView, but can easily be adapted to Spinner by overriding and implementing the GetDropDownView) and Spinner
I have made few Gallery modules by using GridView i have used this tutorial: http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/,
but now this time i want to make it more custom for my usage, i want to Categories Images, Please see below Screen Shot
I will be use static images under specific Categories
How to make this kind of Image Gallery:
I have never tried, but i have found this sample code, and please try to custom it as you like:
http://blog.blundell-apps.com/infinite-scrolling-gallery/
you can do it by implementing Jeff Shrkey's SeperatedListadapter
http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/
and you can
Look 1
Look 2
There isn’t an easy way of creating these separated lists, so I’ve put
together SeparatedListAdapter which does it quickly. To summarize,
we’re creating a new BaseAdapter that can contain several other
Adapters, each with their own section headers.
Create a Layout having a TextView and custom ListView. in each listItem have a GridView. and Load GridItems.
The TextView is for the Category Name.
Basically you must combine, the Custom ListView Implementation and GridView Implementation to achieve your objective. You can find Separate Tutorials for doing the same in the same androidhive website. But, you must work on combining them into one.
I have some data in my data base and i want to display it in android phone.I want to display my data on Grid-view because there is continuous variation in my data therefore i want to display in android like asp.net gridivew.Please anyone help me to do this or any example code to do this
You need to have two things for the Gridview:
Use Gridview component in a layout.
Inflate the elements in a getView method and set elements position by position to the Gridview items.
You can follow this link to understand it:
http://android-coding.blogspot.in/2011/09/simple-gridview-example.html
You are on the right track as you have decided yo use a dynamic view for your varying data. You can use any one of the dynamic view(list view, grid view, gallery, etc) depending on the kind of data you need to display.
If you are not familiar with these dynamic views then you should first go through some tutorials on implementation of these views. First try with a basic program for understanding the concepts. Once you are clear with the concepts then all you need to do is to replace the underneath data with the data fetched from the data base.
There are lots of tutorial available on net. Here are some links:
GridView tutorial
ListView tutorial
Feel free to discuss in case there is any doubt.