NOTE:

NOTE: Of late, I have been getting requests for very trivial problems that many of you are facing in your day-to-day work. This blog is not to solve your "project" problems - surely not a "Support" site.
I just love to share my knowledge in my spare time and would appreciate any questions or feedback on the articles and code I have shared. I also do appreciate thought-provoking questions that would lead me to write more articles and share.
But please do not put your day-to-day trivial problems here. Even if you do, you most probably would not get a response here.
Thanks

Search This Blog

x

Tuesday 20 April 2010

Custom ListView | Android Developer Tutorial (Part 17)

Now, we shall look at creating a custom list view – a custom layout, a custom row layout and how we bind the custom data holder to these layouts. (please see the earlier article on simple list view for the fundamentals of list view).

So, here again, we start with extending ListActivity.
public class MyCustomListView extends ListActivity {

Now let us create the custom list view in an xml file – custom_list_view.xml. This will be set using the setContentView() in onCreate() method:
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000fff"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFff00"
android:text="No data"
/>
Note that it must contain a ListView object with android:id="@id/android:list"

I have also declared a TextView which should be whon when the list if empty by declaring with android:id="@id/android:empty"

Now we will declare how each row in this ListView should be displayed by creating a new xml file – custom_row_view.xml

I plan to have 3 items one below the other in each row. So, here is the declaration for the same:
<TextView android:id="@+id/text1"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#FFFF00"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/text2"
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/text3"
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
So, now, how do I tie all of this together? The MyCustomListView class, the listview layout and the row layout. Just like in the earlier example, we need a ListAdpater object. Here I plan to use a SimpleAdpater provided by the SDK.

An adapter expects the context, the layout and the handle to the data that needs to be displayed. So, let us create a list of data in an ArrayList of HashMaps. This way, the HashMap can store any amount of data.

static final ArrayList<HashMap<String,String>> list =

new ArrayList<HashMap<String,String>>();
This is just a declaration of the list object. We need to populate it with data. Our custom row layout expects each row to have 3 prices of data…

This list is populated in a method as shown below with the 3 keys as ‘pen’, ‘price’ and ‘color’:

private void populateList() {
HashMap<String,String> temp = new HashMap<String,String>();
temp.put("pen","MONT Blanc");
temp.put("price", "200.00$");
temp.put("color", "Silver, Grey, Black");
list.add(temp);
HashMap<String,String> temp1 = new HashMap<String,String>();
temp1.put("pen","Gucci");
temp1.put("price", "300.00$");
temp1.put("color", "Gold, Red");
list.add(temp1);
HashMap<String,String> temp2 = new HashMap<String,String>();
temp2.put("pen","Parker");
temp2.put("price", "400.00$");
temp2.put("color", "Gold, Blue");
list.add(temp2);
HashMap<String,String> temp3 = new HashMap<String,String>();
temp3.put("pen","Sailor");
temp3.put("price", "500.00$");
temp3.put("color", "Silver");
list.add(temp3);
HashMap<String,String> temp4 = new HashMap<String,String>();
temp4.put("pen","Porsche Design");
temp4.put("price", "600.00$");
temp4.put("color", "Silver, Grey, Red");
list.add(temp4);
}
So, now how do we tie up the data with the row layout and the listview layout. It is in this simple piece of code in the onCreate() method of MyCustomListView class:
setContentView(R.layout.custom_list_view);
SimpleAdapter adapter = new SimpleAdapter(
this,
list,
R.layout.custom_row_view,
new String[] {"pen","price","color"},
new int[] {R.id.text1,R.id.text2, R.id.text3}

);
populateList();


setListAdapter(adapter);
Here we have set the default view to custom_list_view.
Then, using the SimpleAdapter, we have set the context, the list containing the data for display, the custom_row_view, the keys by which the data has to be fetched from the list, the TextViews into which the corresponding data has to be displayed.

Now execute and you will have a custom list view. Here is what you will get to see:


NOTE: if you do not populate the list with any data, you will see another view – the empty listview that we have defined in the custom_list_view.xml

You can download the complete source code for this example here.

Added later:
Based on a question below, I would like to add that an item can be clicked even in this custom list and the even captured by overriding the onListItemClick() method on the ListActivity class.

Here is the piece of code you can add to my sample, if you haev downlaoded and ti will toast a message on what has been selected:



protected void onListItemClick(ListView l, View v, int position, long id) {

    super.onListItemClick(l, v, position, id);
    Object o = this.getListAdapter().getItem(position);
    String pen = o.toString();
    Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();
}

Enjoy....

130 comments:

  1. Really your tutorial helps me lot....
    Can you please post tutorial of using ActivityGroup.

    ReplyDelete
  2. hi,
    Do u have any idea about dex cache.. SOme times (not all time) i am getting an some logs like this and my application fails.. Any idea what can be the reason ??

    dalvikvm: Can't open dex cache '/data/dalvik-cache/system@app@myapp.apk@classes.dex': No such file or directory
    04-11 02:26:37.345 1245 1245 I dalvikvm: Unable to open or create cache for /system/app/myapp.apk (/data/dalvik-cache/system@app@myapp.apk@classes.dex)
    04-11 02:26:37.350 1245 1245 D AndroidRuntime: Shutting down VM

    Jins

    ReplyDelete
  3. In my world, HashMap is a heave weight object. If there are many rows, this might become a prolem.

    Is there any way to do this without using hash maps?

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. how to code to get its click event?

    ReplyDelete
  6. Hi Khine,

    You just have to override the protected method on ListActivity - onListItemClick to capture the click event. I have added the same piece of code from the simple listview here.:

    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Object o = this.getListAdapter().getItem(position);
    String pen = o.toString();
    Toast.makeText(this, "You have chosen the pen: " + " " + pen, Toast.LENGTH_LONG).show();
    }

    This should work for you.

    ReplyDelete
  7. Hi Anonymous,

    Regarding the Hashmap being a heavy object, I agree. in my example, the data is hardcoded and hence I had to use hashmaps. However, in real applications, I would imagine that the data is coming from come content provider or SQLite DB and you could just iterate through the resultset and reuse a single collection object to populate the list. Just my thoughts... any other way you discover, feel free to share.

    ReplyDelete
  8. hi,
    thanks for your tutorial. I want to know, how to get value of listview set to onclicklistener, because in listview using position of array listview, not the value of listview itself. Thank you. Sorry for my english.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. i want a listview with icon as image with two line of text.how i ll do please help any one.

    ReplyDelete
  11. Your code worked like charm along with Toast, but i want to get the individual values of price and color, How do i do that? I am a newbie programmer in java

    Thanks in advance

    ReplyDelete
  12. how to create multi column ListView in gridview form in android?
    I would be very thankful to u?

    ReplyDelete
  13. Hi Sai Geetha!
    I have got a problem about event handler in my customized listview
    My ListView have: ImageIcon, TextView and an ImageButton. As ListView14 example in API demos, i creat a classes extended BaseAdapter. In getView()

    if(view == null) {
    mHolder = new ViewHolder();
    view = mInflater.inflate(R.layout.custom_list_item, null);

    mHolder.song_icon = (ImageView) view.findViewById(R.id.music_icon);
    mHolder.song_name = (TextView) view.findViewById(R.id.music_song_name);
    mHolder.song_price = (TextView) view.findViewById(R.id.music_price);
    mHolder.song_view = (TextView) view.findViewById(R.id.music_view);
    //mHolder.play_btn = (ImageButton) view.findViewById(R.id.play_btn);
    ((ImageButton) view.findViewById(R.id.play_btn)).setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
    // TODO Auto-generated method stub
    Toast.makeText(mContext , "Button Clicked: " +
    mMusic.get(mPosition).name, Toast.LENGTH_LONG).show();
    }
    });


    view.setTag(mHolder);
    } else {
    mHolder = (ViewHolder) view.getTag();
    }


    And now i want to handler event for each item(ImageView, TextView, and Button) by clicked on ImageButton an i want recervice text in TextView correlative with each ImageButton. Now, i have no idea to solve this problem. Please notify me when you have some ideas!
    Thanks in advance!
    Notify me via: khaintt@gmail.com

    ReplyDelete
  14. hi there. i loved this tuto. but i have a question. when we click on item appears a Toast text with {color=Silver, Price=500.00$, pen=Sailor}, but i want to appear just value of the tag pen without {}. how can i do this? thanks and waiting for your answer here or to my email lpedro1984@gmail.com .

    ReplyDelete
  15. Hi Luis,

    This is very simple Java code. When I convert the whole HashMap to String, it is showing with braces. Instead of converting the Object to String directly, convert it back to HashMap and retrieve the value for the key "pen".

    Here is the code for the same:

    HashMap fullObject = (HashMap)o;
    Toast.makeText(this, "You have chosen the pen: " + " " + fullObject.get("pen"), Toast.LENGTH_LONG).show();
    }

    ReplyDelete
    Replies
    1. Thanks you so Sai Geetha.. Your posts are really great....!!!

      Delete
  16. Sai Geetha you're the best! really... thanks.

    ReplyDelete
  17. Hello, Thanks for the tutorial. I just had a question and may be you can help me out with that. Can I have the List View with a progress bar inside and not inherit my class from List Activity (I want the ListView to be scrollable part of my Linear Layout). Thanks and appreciate your feedback. Please reply so I can get a notification in my email.

    ReplyDelete
  18. Really your tutorial helps me for custum ListView but i need help Geeta where Custum ListView have icon image in the leftside and 3 line of text will display name,address and phonenumber .

    ReplyDelete
  19. How would you change the typeface of text1 to a custom one ??

    ReplyDelete
  20. I think there must be a cheat inside your code, every time I put other Strings than yours into it stops working and shows just empty rows? (the right amount of rows, but empty ones) :X

    ReplyDelete
  21. I have to apologies, it was my fault, I screwed the workbench properties so awfully that it started making strange things with the R file .. so plz forget about my post above

    tipp for the rest of the readers: think first than post (or u r becoming blamed like me)

    ReplyDelete
  22. Hello Sai Geetha,

    Simply u r d best.....

    Regards,
    Anji

    ReplyDelete
  23. Hi,

    Pretty nice , informative and easy to follow tutorial.

    And, hey can you help me with this one. I have a rowlayout in my custom adapter that has a button and two text views. How can I get the text of the button? I am currently using something like this: String btnText = ((Button)clickedView).getText();

    It works fine. But, sometimes throws Android Runtime ClassCastException.

    Kindly help!

    ReplyDelete
  24. Hi Sai Geetha,
    I have a question.. can we select only one text view out of 3 text views you have added in each list item???


    Ex: I want to select(click) only on "COLOR" textview out of "PEN" "COST" and "COLOR" from 1 listitem???

    ReplyDelete
  25. Hi Sai Geetha. I would like to ask how to edit the value of pen onItemClicked. Thanks

    ReplyDelete
  26. http://mfarhan133.wordpress.com/2010/10/14/list-view-tutorial-for-android/

    This a simple android list view tutorial, you can also apply onClick listener,, complete source code is available

    ReplyDelete
  27. http://mfarhan133.wordpress.com/2010/10/14/list-view-tutorial-for-android/

    This a simple android list view tutorial, you can also apply onClick listener,, complete source code is available

    ReplyDelete
  28. Great tutorial!
    I was able to modify it for my use but I am trying to also add an image from a url to the listview how would I do that?
    I already added the image url to the array I just cant render it.

    ReplyDelete
  29. Respected Sai Geetha mam

    i want a listview with imageview,Imagebutton & 3 textview.
    How can i use hashmap? how can i put image view & button in hashmap.
    Plz reply as soon as possible

    ReplyDelete
  30. Respected Sai Geetha mam

    i want a listview with imageview,Imagebutton & 3 textview.
    How can i use hashmap? how can i put image view & button in hashmap.
    Plz reply as soon as possible

    ReplyDelete
  31. Hi,

    I am not able to see color and price only pen value is displaying in the list.

    Plz help me.

    ReplyDelete
  32. Hi,
    Its really good. But why its displaying the repeated values in listview. It should display only once right..?

    ReplyDelete
  33. Hi,

    means every time by opening the app the values are increasing and repeating in listview. What may be the reason..

    ReplyDelete
  34. Hi Abhilash,

    The list if getting repopulated each time onCreate() is called. I have not written anything on the onDestroy() and onStop() Methods to ensure I clear the list before the app is closed.

    That is the reason for the behaviour you are observing.

    ReplyDelete
  35. Hi Sai Geetha,

    Thanks for the reply. But in your previous example i.e basic example on listview, in it's not happening as happening in custom listview i.e repopulating the list. What may be the reason?

    ReplyDelete
  36. Hi,
    I got the solution, just i removed static keyword in the below statement,

    static final ArrayList> list =

    new ArrayList>();

    After removing the static keyword,the list not repopulating.

    ReplyDelete
  37. Very impressive tutorial. I liked it so much because it was so easy to understand and it worked the way it was described. I hope to see more tutorial like this around.

    Thanks for the help!

    ReplyDelete
  38. the above source code shows a list of items in a single line . can you suggest like this
    pen /n
    price /n
    cost /n

    ReplyDelete
  39. Really Really Helped me, I learned very easily and quickly..... Thanks a lot... Thats really great of you :)

    ReplyDelete
  40. Hi Mam, I need to create a customListview which contain Image , Name and a delete button.

    All the three should appear horizontally like,
    --------------------------------------------
    Image Name Deletebutton
    --------------------------------------------
    how this can be done, can you please help on this.

    Thanks,
    Jay

    ReplyDelete
  41. Hi mam,

    your all posts are really awesome.. thanks for such nice examples..

    i wanted to know can we make listview with different headers to show different kind of data..

    like names:

    places:

    events:

    ...

    ReplyDelete
  42. Really Helpful.But I want add Button on each List Item . Who Can I do?

    ReplyDelete
  43. Dear Mam

    how i display contact person photo in custom list view.

    tell me how i refresh my listview(UI) when i get new message through broadcastReceiver. i update myArrayAdpater with notificationDataChanged But no change found on listview so plz. give useful solution

    ReplyDelete
  44. This comment has been removed by the author.

    ReplyDelete
  45. Hi Sai Geetha...

    This is really educative blog.
    I am fresher to android.
    i have one question for you:

    what modification should i do if i want a new window( new view) to show up, upon clicking any of the list items.

    i found for buttons but what in the case of text within the list.

    please help me in this.

    please help me for this.

    ReplyDelete
  46. Hi,

    I have to create a list view to display all the values of the hashmap to display the values retrieved from the database. In your example to create CustomListView you have hard coded the hashmap values. can you suggest me a way to create a array of hashmap

    Here is something which i've tried

    private void populateList() {
    HashMap temp = new HashMap();
    for(int j=0;j<name1.length;j++)
    {
    temp.put("name",name1[j]);
    temp.put("tel", telephone1[j]);
    list.add(temp);
    }
    }

    ReplyDelete
  47. Thanks a lot for the good tutorial

    ReplyDelete
  48. very very very very awesome...!!!! Thanks Alot

    ReplyDelete
  49. further can you please make a tutorial for ListView with Images also...
    Something like lazy list...

    But in simple way just like the above...!!!
    Thanks alot in advance.

    Awais

    ReplyDelete
  50. Thanks a lot
    I tried & worked fine;

    ReplyDelete
  51. How do we add image into custom_row_view

    ReplyDelete
  52. i dont know how to thankfull to i am...

    ReplyDelete
  53. thanks a lot..
    this very helpful for me.

    ReplyDelete
  54. Simple and beautiful tutorial thank you :)

    ReplyDelete
  55. You have beautiful mind. Thanks a lot.

    ReplyDelete
  56. thanks for all tuts,
    but for this i add some other data in it but only 5 items are displaying suggest me solution.
    thanks.

    ReplyDelete
  57. thanks for it,it helps me a lot..

    ReplyDelete
  58. hi, could you help, please? :]

    Do you remember what happen when there are a listview that contains some icons (about three icons), and I touch the screen and scrollup or scrolldown, so the list (of icons) moves and following my finger.

    So I remove my finger from screen and the list back to the original position (because have less icon then the size of screen). Look this effect.

    Well, my problem is that I have a activity and in this activity I've a View (HorizontalScrollView) and it don't have the same effect, like Listview. The icons (or other views) inside HorizontalScrollView just follows to touch event, but when it leaves the icons(views) stay at the position where it stopped.

    As I don't find a horizontal listview, I'm trying to use scrollview with this effect. Do you know how to do this?

    Thanks for your attention

    ReplyDelete
  59. great work done mam...your tutorials are always very helpful

    ReplyDelete
  60. Hi,

    I was wondering how to get the listview to differentiate between a long click and a regular click? I noticed there was no onLongListItemClick method in the ListActivity class.

    Thanks!

    ReplyDelete
  61. how to make a list as a default list and i want to insert a button in the list view,how do we do this.ur blog is helping me a lot .please help me in this issue

    ReplyDelete
  62. hi, i am rajeshkumar, new to android i want tutorials(with best example) for android..


    Thank You..

    ReplyDelete
  63. Hi, I am Padmanabhan. I use Listview in an activity and inflate with button.How i get the Button click event of button within the listview.

    ReplyDelete
  64. Hai mam, i am fresher to android field..i am doing the program using listactivity..In this program i have the list and textview.the textview is used to display the heading for the list..but the textview is repeated for every item.pls clarify my doubt mam.Thanks in advance

    ReplyDelete
  65. Is there a way to not extend the ListActivity class and still use listview? I still want to extend Activity class. I'm kinda new to Android.

    ReplyDelete
  66. +1 for last comment! Having issues trying to have a dynamic list view without ListActivity.

    ReplyDelete
  67. Figured it out! Here ya go:
    https://gist.github.com/1256137

    ReplyDelete
  68. hi
    i need to add row dynamically to multicolumn listview. can u pls guide me?

    ReplyDelete
  69. hi, I wantthe code for empty listview with three columns with the heading of names,phnos,favourites in XML,java in android...please help me its urgent looking for u r code

    ReplyDelete
  70. Hai mam

    In my listview values are repeating.I am using sqlite database.please help me.it will be useful for my application

    ReplyDelete
  71. protected void onListItemClick (ListView l, View v, int position, long id){
    super.onListItemClick(l, v, position, id);
    setContentView(R.layout.mylayout);
    }

    I want that instead of Toast to get a new layout with a textview, I have tried the code below but I get some truble about "mylayout".

    ReplyDelete
  72. @Mamatha, implement onDestroy() method
    @Override
    public void onDestroy(){
    super.onDestroy();
    list.removeAll(list);
    }

    ReplyDelete
  73. Hi..
    I am creating customized list with multiple selection with help of Checkbox. At last i managed to set checkbox selected on list's item selection's event.

    but when I check boxes are not being selected according to list's selection When I click on first row 4th row's check box gets clicked automatically . In short sequence is not maintained. The code with I am working is as below

    ListAdapter adapter = new SimpleAdapter(
    this,
    Datalist ,
    R.layout.customlist,
    new String[] {"fileName","contentLength","keyPath"},
    new int[] {R.id.title,R.id.size, R.id.path}
    );
    setListAdapter(adapter);

    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    ViewGroup group=(ViewGroup)v;
    CheckBox check=(CheckBox)group.findViewById(R.id.sharecheckbox);
    check.toggle();
    }

    ReplyDelete
  74. How can i add a button to a list view using hashmaps?

    ReplyDelete
  75. Thanks for this great tutorial .Now I have a problem in which i have to view image from url and display it in listview .So please suggest me how to solve this problem .
    You can send me on id androiddilip78@gmail.com
    Thanks

    ReplyDelete
  76. Nice tutorial.

    I need to implement an "OnListItemClick()" which can change the text-size of ListItem and row-size.

    Any recommended way ?

    ReplyDelete
  77. Thanks dude..!!! This tutorial helped me to over come lots of difficulties on list view in Android.. Best Regards...!!!

    ReplyDelete
  78. Thanks! I'd spent hours trying to figure this out, and your tutorial worked the first time! :)

    ReplyDelete
  79. please see the question and help me.
    http://stackoverflow.com/questions/8544418/how-to-show-arrayadapters-text-and-icon-in-list-in-android

    ReplyDelete
  80. Is there any way to do with out using hashmap.
    If i get the 1000 values from databases then i need to create 1000 hashmaps with this code.
    Is there any simple way to do it.

    Thanks

    ReplyDelete
    Replies
    1. how to add values to listview at run time on button click from edit text.
      if you know please send me a code on krunal_mca41286@yahoo.com

      Delete
  81. Hi geetha

    I am naresh. i want to develop an application like mobile backup.

    in this one thing i thought is ""when ever i send a msg from another mobile with a keyword then the missed mobile has to swithoff whenever the msg is opened"" is it possible or not in android???

    ReplyDelete
  82. This is AWESOME! Thank you so much for this.

    ReplyDelete
  83. Thank you very much for this short and very very helpfull example!!!!!!!!!

    ReplyDelete
  84. This is one of the amazing post.I like your blog advantages.This is one of the nice post.Thanks for share with us.

    ReplyDelete
  85. Hi,Mam
    I m retrieving values from database and displaying it in a list.but the problem is my custom xml has 5 textview and 3 buttons i dont want the row to be clicked only the buttons should clickable and values should display in another acivity.Please tell me how to solve this..
    adapter = new SimpleCursorAdapter(this,R.layout.customlist,cursor,
    new String[] {"JOB_TITLE","JOB_START_DATE","JOB_END_DATE","JOB_STATE","JOB_SPECIALITY","JOBPERMANENT",},
    new int[] {R.id.Title,R.id.StartDate,R.id.EndDate,R.id.State,R.id.Speciality,R.id.JobType});
    listview.setAdapter(adapter);

    Thanks and Regards
    Girish

    ReplyDelete
  86. HI...
    I am new in android development..
    I have a list view...the data of a listview is parsed from the xml file.
    I want to put image in list view how can i do that???
    Image is come from the URL...
    please help me abt source code....

    ReplyDelete
  87. check this out -
    Custom ListView with sliding view for each list/row
    http://android-coding-tuts.blogspot.in/2012/02/custom-listview-with-sliding-view-for.html

    ReplyDelete
  88. Hi, can anyone help?

    lets say there is no price for Parker pen. This will leave an empty row in the listview. Can i get rid of this row?

    temp2.put("pen","Parker");
    //temp2.put("price","400.00$");

    Reason for this is that i am building app with name, phone1, phone2 and phone3. not everyone will have the phone2 and phone3 data and so it shows 2 empty rows in the listview. is there anyway to supress these empty rows? i set the textview height to wrap_content but it is not doing anything :(

    ReplyDelete
  89. Hi

    I want sample code for list view with multiple columns with check box and i want get the selected item.
    please i am looking for your response

    ReplyDelete
  90. Thanks for this great Tutorial.but tell me how to display listview in table formate like excel sheet .

    ReplyDelete
  91. Mam please give me example of customized list view which contain different layout for row eg sender has differnt layout and receiver has different

    ReplyDelete
  92. Hi mam,
    Pls send me customized list view example. List view contains senders and receivers message. Sender has different layout and receiver has different.
    I have created listview but when scroll down or up there is problem.

    ReplyDelete
  93. Awesome tutorial, easy to follow and implement. Thanks!!!

    ReplyDelete
  94. Sai Geetha

    Thank you many times over for this post, it brought the whole process into focus for me, and I was able to go from your example to a fill-the-list-from-a-cursor very quickly.

    Now I find I have to go further. Some of the text rows in my db will need to contain markup - and from what I've read that means they need to be fed to the their textviews as SPANS instead of as STRINGS.

    Can simpleadapter handle this somehow? Or do I need to write my own?
    Any direction you can give would be greatly appreciated.

    ReplyDelete
  95. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hi Sai Geetha,
      This is very nice blog i always refer this blog for android.
      i want to set the dynamic scroll height for my (dynamic hashmap) i mean for dynamic list item
      eg.

      my listview layout is as follows..

      android:id="@id/android:list"
      android:layout_width="fill_parent"
      android:layout_height="2400dp"
      android:cacheColorHint="#00000000"
      android:divider="#736F6E"
      android:dividerHeight="1dp"
      android:fadingEdge="none"
      android:layout_weight="2"
      android:listSelector="@drawable/strip"


      in above example i have mentioned android:layout_height="2400dp"
      i want to set this height run time as per the content.
      Please help me in this....
      Thanks
      Mohsin

      Delete
  96. Nothing special
    Everyone have posted this kind of blogs....
    So some extra...
    Showing Toast instead change layout..

    ReplyDelete
    Replies
    1. Why cant you shut up!! if it is not good then don't see...

      Delete
  97. dam gud example!!! i have done it...
    Thanks a lot....

    ReplyDelete
  98. I download data from google places api.I save icon,name,add etc.
    I uses your customised layout.
    This is my code .....
    earthquakes = json.getJSONArray("results");

    for(int i=0;i();
    e = earthquakes.getJSONObject(i);

    map.put("id", String.valueOf(i));
    map.put("icon", "" + e.getString("icon"));
    map.put("vicinity", "" + e.getString("vicinity"));
    map.put("name", "" + e.getString("name"));
    strurl=e.getString("icon");

    mylist.add(map);
    }
    }catch(JSONException e) {
    Log.e("log_tag", "Error parsing data "+e.toString());
    }


    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.aa,

    new String[] {"icon","name", "vicinity" },
    new int[] {R.id.imageihavefun,R.id.item_title, R.id.item_subtitle } );

    setListAdapter(adapter);

    Now my question is How can I show this icon.
    Please help me from this.
    Thanks and Regards,
    Maidul

    ReplyDelete
  99. Hi Sai,

    I am making a web service sample project using 8 coupouns API.
    I have created JSOn model in a class Coupouns.class

    Here is my code:

    package com.preeti.model;

    public class Coupouns{
    public String chainID;
    public String homepage;
    public String logoBig;
    public String logoSmall;
    public String name;
    public String page;
    }

    I have show these values of these Coupouns class in activity.
    Could you please tell me how to get the values whether we will use ArrayAdapter here?

    I am new to programming and struggling to learn android.

    ReplyDelete
  100. Hi Sai = fantastic blog and still very relevant.

    thanks

    anton

    ReplyDelete
  101. Hi, I don't have your email ID and therefore I am sending your this request via a comment. Would you be interested in writing a blog comparing the following libraries for writing list adapters with sections?

    https://github.com/commonsguy/cwac-merge
    https://github.com/ragunathjawahar/simple-section-adapter
    http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/

    Please let me know. Thank you.

    ReplyDelete
  102. awesome .. thanxs so much from Venezuela

    ReplyDelete
  103. Hai..Its really works fine...I want sample coding for delete and add some more item to listview

    ReplyDelete
  104. Superb. Explanations to the point and very clear

    ReplyDelete
  105. Hi,

    nice tutorial,

    one question: why do you say about the custom list view "Note that it must contain a ListView object with android:id="@id/android:list""???

    Keep up the good work!

    Thanks for it!

    ReplyDelete
  106. Hi geetha,

    I Have small doubt in touch events
    My problem is im using 9 buttons and eacch one each touchlistner but only one touch button is true remaining all are false plzzzzzzzzzzzzzzzzz rly me the code

    ReplyDelete
  107. can u please host your code in some place other than mediafire because that site is banned in our college :-(

    ReplyDelete
  108. Hi could u tell me how to set edit text & text view side by side plzzzzzzzzzzz

    ReplyDelete
  109. Thanks very help -- full

    I suggest you charge for responses =p

    ReplyDelete
  110. nice artical ,
    how can i remove selected item from listview

    ReplyDelete
  111. Simpleadapter display's twice a value from hashmap value. I tried Listadapter and tried clear() for arraylist too, but i can't get solution. Pls suggest me solution for filtering the value in adapter.

    ReplyDelete
  112. Excellent blog.. was looking for something like this for over a week... solved my problem..

    thanks

    ReplyDelete
  113. amazingggggg!!!!!

    ReplyDelete
  114. what is android?????
    pls help

    ReplyDelete
  115. I want to know sometime listview shows empty list, without data listivew is showing. This kind of things happens normally in fetching json value. I want to display alert message, when data is not load on listview. Please suggest me how to do that.

    ReplyDelete
  116. I a want a accordion effect with the ListView so I want to add the subitem which is to be first hide when I click on list item it show the sub item of a respective list item can u provide some kind of code to do this task plz mail me on nawale.mahesh85@gmail.com

    ReplyDelete
  117. If i try to add data in hash map from table using cursor ,when i add 2nd row data the list shows same data in both row which i added in last and dosnt show previous data. please help me.

    ReplyDelete
  118. This is an awesome short and simple tutorial . Thanks !

    ReplyDelete
  119. This comment has been removed by the author.

    ReplyDelete
  120. Thank you very much!

    ReplyDelete