原文链接:http://wang-peng1.iteye.com/blog/578411
有时候我们想在listView上分类,或者呢 有时候一行显示两列内容,有时候需要三列内容 ,那怎么实现呢,这里呢就要使用
自定义一个类,这个类呢包含多个adapter就可以了,想用那种就用那种。
然后主类就是
public class SectionedDemo extends ListActivity {
private static String[] items={"lorem", "ipsum", "dolor","purus"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
adapter.addSection("Original",new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
items));
List<String> list=Arrays.asList(items);
Collections.shuffle(list);
adapter.addSection("Shuffled",new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
list));
list=Arrays.asList(items);
Collections.shuffle(list);
adapter.addSection("Re-shuffled",new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
list));
setListAdapter(adapter);
}
SectionedAdapter adapter=new SectionedAdapter() {
protected View getHeaderView(String caption, int index,View convertView,ViewGroup parent) {
TextView result=(TextView)convertView;
if (convertView==null) {
result=(TextView)getLayoutInflater().inflate(R.layout.header, null);
}
result.setText(caption);
return(result);
}
};
}
其他的就需要你自己变化了,我这里只是把内容打乱。