Displaying both text and icons in gridview - android

I want to display the icons in grid view and also text heading for that icon just below it.
can some one help me out.

You are supplying an Adapter to the GridView. Have that Adapter return Views for the cells that have icons "and also text heading for that icon just below it". You might use a vertical LinearLayout with an ImageView and TextView children, for example.
Here is a free excerpt from one of my books that shows how to do this sort of thing for a ListView -- the same technique holds for GridView.

If you are beggining in Android like me, I found out that the simplest thing to start with is to:
1) Set each grid to contain a textview
2) Set background (icons in your case) to each textview; plus add the text.
Like:
//textview is a the textview in the cells
textview.setBackgroundResource(<your icon resource>);
The text is added and modified normally:
textview.setTextColor(Color.BLACK);
textview.setTextAppearance(mContext, R.<style xml>);
textview.setGravity(Gravity.BOTTOM);
You'd most likely need to properly set the text position and color so you have a readable result.
Then you may also set the background properties (you can check textview methods)

Related

AutoCompleteTextView - how to add an image and a text to auto completed text?

I have the following layout in my app -
What I want to achieve is the following -
1) The red line - I want to have above the suggestions a hard coded text saying "did you mean" and then the recommended. This text should be replaced when there are 0 characters in the AutoCompleteTextView and say "recent search". How can I do that?
2) The blue line - I want to have an image near each row item - how can I add them?
3) I would like to add a magnifying glass image before the searched text query starts to write. How can I add it?
As stated in the title, I am using AutoCompleteTextView.
You can create custom view for your autocomplete textview and set that view into adapter. custom view contain imageview and textview as you want in horizontal row.
still not getting idea check this Custom view for dropdown

How to add Default Background if ListView / Adapter is empty

Here is an example of what I am saying in title. Take the app "Feedly". If there is even ONE item i your list, it looks like this:
Now, if the list is empty, there is a nice way to handle this to avoid a big, blank, white space, like so:
How can one achieve this?
Off hand I am thinking maybe this way, see my pseudo-code:
if (adapter.size < 1) {
// change ListView Background;
}
Check out the ListView#setEmptyView method.
If your have an empty ListView, the height should be 0 and it may be no use to set the background for ListView.
I have several solutions here:
Set the background for the LinearLayout/RelativeLayout, whatever which contain the ListView according to size of adapter.
Create another ImageView which is the "All read" image, and set its visibility according to data size of the ListView adapter.
Create a view for what you want to display when adapter size = 0, and use ViewSwitcher to switch between ListView and "All read" view according to adapter size. I will recommend this one since it may be more flexible for the "All read" view. You can have button, TextView, ImageView or whatever layout element you want to put in it.
2 and 3 are similar but using ViewSwitcher may make the code readability better than setting Visibility for views.
Here is an example for using ViewSwitcher.

android list item formatting

I have a listview item xml with 3 views - two text boxes and a checkbox.
I need the second textview and the checkbox to always be shown, i.e. they must not get cropped or pushed off the end of the item.
The first textview sometimes contains a long name, and this is making the second textview too narrow and pushing the checkbox off the end of the list item. The first textview needs to be the one that gets ellipsized.
I've tried using android:layout_weight but this makes the views always use the same width, which isn't what I want. For instance if the 2nd textview doesn't contain any text, I want it to completely collapse.
I've tried using various combinations of wrap_content/fill_parent and doing things in code but nothing seems to be working. I am currently using a linearLayout for it.
You can try using TableLayout, setting shrinkColumns to 0, and stretchColumns to "1, 2"
This should allow the checkbox and the second textview to take all available place, and shrink the first textview as necessary

android : How to assign default theme color to TableRow

I have a table in which I add rows dynamically. By default when a row is clicked, nothing is changed so user can't get notification of which row is seected. I want to set the default theme background color for onClick event of row. The main purpose of this is to match its selection with other components of the application.
EDIT :
To make it simpler and easy to understand, here's the exact scenario :
I have a tablayout, that has a tablelayout in it. I am adding TableRow's dynamically that contians 3 TextView's.
On selecting a tab, its color changes fron Gray to Whitish. I want the same color setting to be done on my row selected.
In any situation, I want to make sure that whatever is the color for tab selection that same color is applied to row selection.
This is what my exact requirement is and am looking for a solution from last 2 days. But can't find anything proper.
At present I am changinf row selection by :
currSelectedRow.setBackgroundResource(android.R.drawable.divider_horizontal_bright); // .list_selector_background);
"list_selector_background" occupies that much length below the row and on next row selection that spcae is not evned out. So spaces are left between rows here and there. Similarly, I also tried with "tab...." that also caused the almost same results as list_selector. At present have just used "divider_horizontal_bright" to get the idea of which row is selected. But doesn't get my solution.
I want the selectedtion background colro of tab to be applied to background color of row.
How do I get this info and set the color of the row selected ?
Thanks #Krishna,
But that didn't work out for me. I implemented using onFocusListener and onClick on Table Row and that worked out perfectly. I wanted to use selector, but I guess ..

Android Text not fitting into the List

I make a simple list choice multiple selection option, using an array of String. The text of the list item is very long and wrapped into 2-5 lines. The text is not being fit into the list item boundary if it exids more than 2 rows. The boundary of the List item overlapping the text.
Please let me know how to adjust the height of the List item accoding to the lenght of the text.
Thanks
You need to cut off the text if its very long or wrap everything by adjusting the font?
If you need to adjust with the font you may look into the following question, which I faced and the answer is written by me itself in it...
TextView text shrink to the given width

Categories

Resources