How to display a counting of an item from ListView

user866364

I would like to display a count inside a red circle that displays the news entries for that item. Like email count, know?

Is there anyway that i can do it or the best way is to create a new TextView and implement it?

Thank in advance.

Emanuel Moecklin

Use a TextView with a background image like so:

<TextView
     android:id="@+id/count"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/mybackground"/>

The background image is preferably a 9-patch drawable (http://developer.android.com/tools/help/draw9patch.html) or it could be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#FF0000"/>
    <corners android:radius="4dp"/>

</shape>

This one would draw a red rectangle with rounded corners but you can create any shape you like (http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape)

If you don't want the text to be centered (like at the right bottom corner) you have two options:

Option 1

Make the TextView larger than it would be when just wrapping around the text (which is the default). So either use match_parent for android:layout_width and android:layout_height or set an absolute size (in dp). Also use the gravity parameter to position it at the right bottom corner:

<TextView
     android:id="@+id/count"
     android:layout_width="100dp"
     android:layout_height="100dp"
     android:gravity="right|bottom"
     android:background="@drawable/mybackground"/>

Option 2

Use padding to move the text in the direction you need it to move:

<TextView
    android:id="@+id/count"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:paddingLeft="10dp"
    android:background="@drawable/mybackground"/>

Using two views on top of each other is of course possible too but inefficient. You'd need at least an extra ViewGroup (e.g. FrameLayout) around the TextView (for the counter) and the ImageView (for the background) to make sure they are positioned above each other, meaning you'd replace one TextView by three other views. Also you'd still have to set the size of the enclosing ViewGroup to something bigger than the TextView so there's nothing gained with that solution.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to display item and subitem from HashMap in ListView

From Dev

How To Display Details item from listview

From Dev

How to delete an item from a list and start counting from the next item?

From Dev

How to display clicked listview item in another activity

From Dev

how to get an item from a listview

From Dev

how to remove Listview Item from listview in android

From Dev

how to display a listview when clicked on the item of a listview with the use of arraylist?

From Dev

How to select single item from listview and display resulted name of row in another activity

From Dev

How to select single item from listview and display resulted name of row in another activity

From Dev

how to know if item in listview is pressed/geting listview item from id

From Dev

Display item Listview in Toast

From Dev

Xamarin ListView display item from SQLite Database C# Android

From Dev

Xamarin ListView display item from SQLite Database C# Android

From Dev

How to update sqlite listview item from adapter?

From Dev

How to remove an item from a Xamarin Forms ListView?

From Dev

How to delete item from listView using alertDialog

From Dev

how take text from selected listview item

From Dev

How get item from a listView Android?

From Dev

How to delete item from listView with custom baseadapter

From Dev

How to Delete Item From Listview on Android

From Dev

How to Display a new view while long pressing an item in the ListView?

From Dev

How to manage item position when ads banner display inside in listview

From Dev

How to update listview when an item is click from the listview itself

From Dev

Why won't my code display results from an online database? How to make item in ListView clickable to new page showing results?

From Dev

How to display items from the database in listview?

From Dev

How to display items from the database in listview?

From Dev

How to display in listview columns from different tables

From Dev

How to fetch a data from the database and display it on ListView?

From Dev

Display selected ListView item into TextView

Related Related

  1. 1

    How to display item and subitem from HashMap in ListView

  2. 2

    How To Display Details item from listview

  3. 3

    How to delete an item from a list and start counting from the next item?

  4. 4

    How to display clicked listview item in another activity

  5. 5

    how to get an item from a listview

  6. 6

    how to remove Listview Item from listview in android

  7. 7

    how to display a listview when clicked on the item of a listview with the use of arraylist?

  8. 8

    How to select single item from listview and display resulted name of row in another activity

  9. 9

    How to select single item from listview and display resulted name of row in another activity

  10. 10

    how to know if item in listview is pressed/geting listview item from id

  11. 11

    Display item Listview in Toast

  12. 12

    Xamarin ListView display item from SQLite Database C# Android

  13. 13

    Xamarin ListView display item from SQLite Database C# Android

  14. 14

    How to update sqlite listview item from adapter?

  15. 15

    How to remove an item from a Xamarin Forms ListView?

  16. 16

    How to delete item from listView using alertDialog

  17. 17

    how take text from selected listview item

  18. 18

    How get item from a listView Android?

  19. 19

    How to delete item from listView with custom baseadapter

  20. 20

    How to Delete Item From Listview on Android

  21. 21

    How to Display a new view while long pressing an item in the ListView?

  22. 22

    How to manage item position when ads banner display inside in listview

  23. 23

    How to update listview when an item is click from the listview itself

  24. 24

    Why won't my code display results from an online database? How to make item in ListView clickable to new page showing results?

  25. 25

    How to display items from the database in listview?

  26. 26

    How to display items from the database in listview?

  27. 27

    How to display in listview columns from different tables

  28. 28

    How to fetch a data from the database and display it on ListView?

  29. 29

    Display selected ListView item into TextView

HotTag

Archive