2011-01-27 13 views
0

は、私はこの書き込みfeed.if RSSのリストを持っている:リストビューのカスタマイズ

List<String> titles = new ArrayList<String>(messages.size()); 
     for (Message msg : messages){ 
      titles.add(msg.getDate()); 
      titles.add(msg.getTitle()); 

を私はsaperate strings.Iで、タイトルと日付が

titles.add(msg.getDate()+msg.getTitle()); 

にそれを変更しようとしました得るが、これは日付とタイトルをスペースなしで返します。

私は好き日付とその下title.Somethingを持っているしたいと思います:?

Thu 27 Jan 2011 
Bla bla bla.. 

私はそれをどのように行うことができ、また、私はタイトルに日付や他に別のテキストの色やサイズを有することができます?

ありがとうございます!

+1

すべてのリスト項目に2列を持つことが可能だろうと、最初の行で、それはとのタイトルになりますか? 20px textSizeと2番目の日付は14pxサイズです。それは探しています! –

答えて

2

別のアプローチlayout xmlファイルを使用して行のレイアウトを指定し、各メッセージの特定の情報(日付やタイトルなど)を行レイアウトの特定のウィジェットにバインドするアダプタを指定します。

これは良いかもしれ理由は、この方法は、ということであるということである:(メッセージ上の日付をスタッキング)レイアウト情報をXMLにとどまり、コード

  • のうち、それはまた、それが容易になります

    • 将来的にもっと複雑なレイアウトを使用することもできます(カテゴリはどのように表示されますか)。
    • 将来のレイアウトの変更が容易になります。そして
    • それがためにスクロール車種のテキストビューを指定する記述が

    長い場合のように、この例では、複雑な行にListMapのペッドデータをバインドするためにSimpleAdapterを使用して、あなたがより複雑なウィジェットやウィジェット機能を使用することができますリストビューの。

    http://www.vbsteven.be/blog/using-the-simpleadapter-with-a-listview-in-android/

    // get messages from service 
    ArrayList smsMessages = service.getSmsCalls(); 
    
    // initialize the List of Maps 
    List<map> list = new ArrayList<map>(); 
    
    // iterate over all messages 
    // create a map for each message 
    // fill the map with data 
    for (Call c: smsMessages) { 
        Map map = new HashMap(); 
        map.put("number", c.getTo()); 
        map.put("date", DateParser.getTimeString(c.getBegin())); 
        map.put("price", "€ " + c.getPrice()); 
        list.add(map); 
    } 
    
    // the from array specifies which keys from the map 
    // we want to view in our ListView 
    String[] from = {"number", "date", "price"}; 
    
    // the to array specifies the TextViews from the xml layout 
    // on which we want to display the values defined in the from array 
    int[] to = {R.id.callog_detail_sms_number, R.id.callog_detail_sms_date, R.id.callog_detail_sms_price}; 
    
    // get a reference to the ListView 
    ListView lv = (ListView)findViewById(R.id.callog_detail_listview); 
    
    // create the adapter and assign it to the listview 
    SimpleAdapter adapter = new SimpleAdapter(this.getApplicationContext(), list, R.layout.callog_detail_sms, from, to); 
    lv.setAdapter(adapter); 
    

    残念ながら、記事には、レイアウトXMLを示していないが、その下には、次の例のようにになるだろう。実際にフィールドが2つしかない場合、LinearLayoutは問題ありません。より複雑なレイアウトの2つ以上、RelativeLayoutを見て開始します。

    http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="?android:attr/listPreferredItemHeight" 
    
        android:padding="6dip"> 
    
        <ImageView 
         android:id="@+id/icon" 
    
         android:layout_width="wrap_content" 
         android:layout_height="fill_parent" 
    
         android:layout_alignParentTop="true" 
         android:layout_alignParentBottom="true" 
         android:layout_marginRight="6dip" 
    
         android:src="@drawable/icon" /> 
    
        <TextView 
         android:id="@+id/secondLine" 
    
         android:layout_width="fill_parent" 
         android:layout_height="26dip" 
    
         android:layout_toRightOf="@id/icon" 
         android:layout_alignParentBottom="true" 
         android:layout_alignParentRight="true" 
    
         android:singleLine="true" 
         android:ellipsize="marquee" 
         android:text="Simple application that shows how to use RelativeLayout" /> 
    
        <TextView 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
    
         android:layout_toRightOf="@id/icon" 
         android:layout_alignParentRight="true" 
         android:layout_alignParentTop="true" 
         android:layout_above="@id/secondLine" 
         android:layout_alignWithParentIfMissing="true" 
    
         android:gravity="center_vertical" 
         android:text="My Application" /> 
    
    </RelativeLayout> 
    
  • 0
    titles.add(msg.getDate()+" "+msg.getTitle()); 
    

    ...または、あなたがそれら二つの間ENTER持つようにしたい場合は...あなたがHTML文字列でそれをラップする必要があります:少しものの、

    titles.add(msg.getDate()+"<br/>"+msg.getTitle()); 
    // and somewhere else, when you are going to draw it: 
    textView.setText(Html.fromHtml(title.get(position))); 
    
    +0

    申し訳ありませんが、2番目の方法は動作していません...もう少し考えてください? –

    +0

    なぜ機能していませんか?どのようなエラーが出ますか? – Cristian

    +0

    ローカル変数のテキストビューを作成し、位置 –

    関連する問題