Different Icons in List View

前端 未结 4 485
走了就别回头了
走了就别回头了 2021-02-05 16:10

I have to create a list view , with each item getting a separate icon along the right hand side. I have written a code , but its not working ? how do I proceed ? application cra

相关标签:
4条回答
  • 2021-02-05 16:42

    Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

    You are Using ListActivity and also setting content setContentView(). ListActivity by default has a ListView and does not needs an xml layout. However if you want to provide an xml layout, your layout MUST have a ListView element with id set to @android:id/list.

    About the contents, You can always inflate a menu.xml in a Menu and use it like a data Array. Luckily each MenuItem has a title and icon. Also Menu has size() and getItem() methods.

    0 讨论(0)
  • 2021-02-05 16:46

    below some links are useful to for you same code as per your requirement....

    http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

    http://wptrafficanalyzer.in/blog/listview-with-images-and-text-using-simple-adapter-in-android/

    http://android-example-code.blogspot.in/p/dynamic-custoized-list-view-in-android.html

    http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

    OR

       if (menuitems[0] != null) {
                  if(menuitems[0].equalsIgnoreCase("Availability")
                    {
                        icon.setImageResource(R.drawable.menu_availability);
                     // Set your another textview and another subtext here....
                     }
             } 
      // Set another conditions also as per above code
    

    Thanks

    0 讨论(0)
  • 2021-02-05 16:47

    Just Use A HashMap<String,String> that will contain your row details (image, two text). Refer to this link that will help you to achieve what you want.

    enter image description here

    0 讨论(0)
  • 2021-02-05 16:50

    You can get simple Code here, which shows an image and some text in each row of the list:

    http://www.mkyong.com/android/android-listview-example/

    enter image description here

    but if the number of rows is high, and if the image in each row is to be fetched from a server then you better use this:

    https://github.com/thest1/LazyList

    0 讨论(0)
提交回复
热议问题