开发者

Android muticolumn listview with headinng

How can we give the heading for muticolumn list view (Like table heading)

For example I need like this

RouteCode   RouteName   Outelet
 0001        aaaaa        10
 0002        bbbbb        20

But currently display like this

      0001        aaaaa        10
      0002        bbbbb        20

I have done using SimpleAdapter

  ListView list = getListView();
    sd = new SimpleAdapter(this, routhPath, R.layout.route_path,new String[] {"routeCode","routeName","outlets" },new int[] { R.id.routeCode,R.id.routeName,R.id.outl开发者_如何学编程ets});
    list.setAdapter(sd);
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setSelected(true);
    list.setSelection(0);
    list.setTextFilterEnabled(true);
    list.setItemsCanFocus(true);
    list.setItemChecked(positions, true);
    list.setSelectionAfterHeaderView();

My list view also :

 <ListView android:id="@android:id/list" 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" 
              android:clickable="true"
              android:dividerHeight="2dp" 
              android:divider="@drawable/divider"
              android:textFilterEnabled="true"
              android:scrollbars="vertical"
              android:layout_gravity="fill_vertical"
              android:drawSelectorOnTop="false"
              android:clipChildren="true" 
              android:fitsSystemWindows="true"
              android:smoothScrollbar="true"
              android:cacheColorHint="#fff"
              android:fastScrollEnabled="false"
                />

Another question

How to differentiate particular row in the list (differentiate mean different color)? I need this for default route is set in db. then that row should be show with different color. How can i implement this.?

for example when it load i want to show 2nd or 3rd or.. row in red color .. Please help me

Thanks in advance


First question

Do you want a header for a couple of items in the list or just a header for the complete list?

If you just want a header for the list you can use listview.addHeaderView(View v) Or the other addHeaderView, check the link for the two.

Another way of doing it would be to use a custom adapter if you want different headers in the list. Either do your own adapter, there is plenty of different examples out there for custom adapters.

There is also different libraries out there. Two examples for having different headers within the listview is first seperatedlistadapter and another one is CommonsWare MergeAdapter.

Edit: Your second question I would definitely use my own custom adapter for doing this. One great example is here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html In that example they have different drawables for different rows.

        // Bind the data efficiently with the holder.
        holder.text.setText(DATA[position]);
        holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);

Depending on what position is required the image alternates.


I have done first question like this :

 View row = null;
 ListView list = getListView();
    sd = new SimpleAdapter(this, routhPath, R.layout.route_path,new String[] {"routeCode","routeName","outlets" },new int[] { R.id.routeCode,R.id.routeName,R.id.outlets});
    row = getLayoutInflater().inflate(R.layout.route_path_row, null, false);
    getListView().addHeaderView(row);

I have created 2 xml for list contents .one is header another one is row.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜