• Contact us
  • TopTipsTips6

    [Tips6] Add ListView in Android Tabhost

    Web 2.0 time,twitter,follow5,sina micro blog become more and more popular.Android has achieved 13% in US.Android application getting more and more in Android market,there are also other markets have. These months I have been making a micro blog client.Refer to the other Android micro blog client,I discovered someone make the picture quite beautiful by webiew.Majority are also use Android Internal controls.Now I reference shoushou's tab,try to write a demo.

    ■ 1, Setting layout

    Now,first to write xml.There are one frameLayout and four AbsolutelyLayout in xml:

    Of course,you can adjust the layout by your means. You can also look the eoe course “tabhost and tab” to lean how to add tab in code.

    tabhost and tab

     

    ■ 2, Gains the listview through the network

    Now,let's add the code. I want to use the resources on the network and displayed by listview .For example ,follow5.

    Follow5 is a good micro blog in China,api opening use. But you must get an apikey then you can going to development.

    You can click here to know more about it. http://www.follow5.com/f5/jsp/other/api/api.jsp After get the apikey, you can use the newest share in follow5 .There is an api does not need user name and password:
    http://api.follow5.com/api/statuses/public_timeline.xml? api_key=****
    Now,you can get a lots of xml files.You can use the xml resolver to analyze.After the analysis completes,you can put the date in arraylist for backup.You must be familiar with xml analyze.You can use sax or xmlpullparser to analyze xml file. I think it is not a good idea to use dom,because it occupy too much resources.You can click these two links to learn sax or xmlpullparser analyze.
    http://www.javaeye.com/topic/41564
    http://www.javaeye.com/topic/401377

    ■ 3, Fill the listview

    The most important thing is how to fill the data in listview. For example,let us put the data in ArrayList. There are contents in listview. Listview internal layout is already defined . This is the code:



    And then to add data formats:


    MyImageBinder rewrites ViewBinder , it's operation to the text and image in ArrayList. If you want to know more about it,you can click the link to download the source code:

    Crowdroid1.2.0_source.zip(Multifunction Micro Blog Client )

    Micro blog starts abundantly late in China,but it became more and more popular.Also there are some micro blog has not open, but sina、follow5 are use well in China.I hope there is an only one api.First,it good for the developers.And then people can easy to promotion the company's product.

  • Contact us
  • Press Release
  • Anhui Opensource Inc.

    Copyright (C) Anhui OSS All Rights Reserved.