FAQ

[android-developers] Implementing TwoLineListItem

Bernard FitzGerald
Jun 14, 2012 at 9:59 am
Hi all,

Does anyone have any sample code of how to implement a
TwoLineListItem.

So far I have been able to create a custom LinearLayout with two
TextViews and have gotten this working but I believe I should be using
a TwoLineListItem to acheive this. My issue is that I can't seem to
implement the TwoLineListItem.

In my main layout I add a ListView and then I also create another
layout xml file named list_item that contains a linearlayout with a
twolinelistitem.

In my java class I add items to a list of a HashMap<String, String>. I
create a SimpleAdapter as follows:

SimpleAdapter myAdapter = SimpleAdapter(this, list,
R.layout.list_item_new, new String[] { "line1", "line2" }, new int[]
{ R.id.text1, R.id.text2 });

Then:

myAdapter.notifyDataSetChanged();
setListAdapter(myAdapter);

I would of thought that this would populate my list but no. Can anyone
help me with this?

Thanks, Bernie.




--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
reply

Search Discussions

2 responses

  • Justin Anderson at Jun 14, 2012 at 5:14 pm

    Does anyone have any sample code of how to implement a
    TwoLineListItem.
    http://lmgtfy.com/?q=android+TwoLineListItem+tutorial

    So far I have been able to create a custom LinearLayout with two
    TextViews and have gotten this working but I believe I should be using
    a TwoLineListItem to acheive this. My issue is that I can't seem to
    implement the TwoLineListItem.
    If you've got something working then I wouldn't worry about it. "If it
    ain't broke, don't fix it." :-) That being said, if you are really dead
    set on using it, then look at the link above...

    myAdapter.notifyDataSetChanged();
    setListAdapter(myAdapter);
    I may be wrong, but I believe you need to set your adapter before calling
    notifyDataSetChanged()

    Thanks,
    Justin Anderson
    MagouyaWare Developer
    http://sites.google.com/site/magouyaware

    On Tue, Jun 12, 2012 at 5:41 PM, Bernard FitzGerald wrote:

    Hi all,

    Does anyone have any sample code of how to implement a
    TwoLineListItem.

    So far I have been able to create a custom LinearLayout with two
    TextViews and have gotten this working but I believe I should be using
    a TwoLineListItem to acheive this. My issue is that I can't seem to
    implement the TwoLineListItem.

    In my main layout I add a ListView and then I also create another
    layout xml file named list_item that contains a linearlayout with a
    twolinelistitem.

    In my java class I add items to a list of a HashMap<String, String>. I
    create a SimpleAdapter as follows:

    SimpleAdapter myAdapter = SimpleAdapter(this, list,
    R.layout.list_item_new, new String[] { "line1", "line2" }, new int[]
    { R.id.text1, R.id.text2 });

    Then:

    myAdapter.notifyDataSetChanged();
    setListAdapter(myAdapter);

    I would of thought that this would populate my list but no. Can anyone
    help me with this?

    Thanks, Bernie.




    --
    You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to android-developers@googlegroups.com
    To unsubscribe from this group, send email to
    android-developers+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en
    --
    You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to android-developers@googlegroups.com
    To unsubscribe from this group, send email to
    android-developers+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en
  • Bernard FitzGerald at Jun 14, 2012 at 8:37 pm
    Thanks for the that. I'd googled around (a lot) until I found a good way of implementing it. Found a solution here
    http://beginnerdroid.wordpress.com/
    It was all in the detail as they say. I just had to create a customised ArrayAdapter and I was fine.
    Thanks!

    From: mag...@...com
    Date: Thu, 14 Jun 2012 11:13:18 -0600
    Subject: Re: [android-developers] Implementing TwoLineListItem
    To: android-developers@googlegroups.com


    Does anyone have any sample code of how to implement a

    TwoLineListItem.

    http://lmgtfy.com/?q=android+TwoLineListItem+tutorial



    So far I have been able to create a custom LinearLayout with two

    TextViews and have gotten this working but I believe I should be using

    a TwoLineListItem to acheive this. My issue is that I can't seem to

    implement the TwoLineListItem.

    If you've got something working then I wouldn't worry about it. "If it ain't broke, don't fix it." :-) That being said, if you are really dead set on using it, then look at the link above...



    myAdapter.notifyDataSetChanged();
    setListAdapter(myAdapter);

    I may be wrong, but I believe you need to set your adapter before calling notifyDataSetChanged()



    Thanks,

    Justin Anderson

    MagouyaWare Developer

    http://sites.google.com/site/magouyaware



    On Tue, Jun 12, 2012 at 5:41 PM, Bernard FitzGerald wrote:


    Hi all,



    Does anyone have any sample code of how to implement a

    TwoLineListItem.



    So far I have been able to create a custom LinearLayout with two

    TextViews and have gotten this working but I believe I should be using

    a TwoLineListItem to acheive this. My issue is that I can't seem to

    implement the TwoLineListItem.



    In my main layout I add a ListView and then I also create another

    layout xml file named list_item that contains a linearlayout with a

    twolinelistitem.



    In my java class I add items to a list of a HashMap<String, String>. I

    create a SimpleAdapter as follows:



    SimpleAdapter myAdapter = SimpleAdapter(this, list,

    R.layout.list_item_new, new String[] { "line1", "line2" }, new int[]

    { R.id.text1, R.id.text2 });



    Then:



    myAdapter.notifyDataSetChanged();

    setListAdapter(myAdapter);



    I would of thought that this would populate my list but no. Can anyone

    help me with this?



    Thanks, Bernie.









    --

    You received this message because you are subscribed to the Google

    Groups "Android Developers" group.

    To post to this group, send email to android-developers@googlegroups.com

    To unsubscribe from this group, send email to

    android-developers+unsubscribe@googlegroups.com

    For more options, visit this group at

    http://groups.google.com/group/android-developers?hl=en




    --

    You received this message because you are subscribed to the Google

    Groups "Android Developers" group.

    To post to this group, send email to android-developers@googlegroups.com

    To unsubscribe from this group, send email to

    android-developers+unsubscribe@googlegroups.com

    For more options, visit this group at

    http://groups.google.com/group/android-developers?hl=en

    --
    You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to android-developers@googlegroups.com
    To unsubscribe from this group, send email to
    android-developers+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en

Related Discussions

Discussion Navigation
viewthread | post