带部分的 Android Listview
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10319109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Listview with sections
提问by iamlukeyb
Hi I am having an issue trying to understand how sectioned ListViews work. I had it working into a normal list view. but now I want to add sections to my list. How to I ad a section header in.
嗨,我在尝试了解分段 ListViews 的工作方式时遇到问题。我让它在一个普通的列表视图中工作。但现在我想将部分添加到我的列表中。如何在其中添加节标题。
Heres my code that works.
这是我的工作代码。
public class ChooseTeamActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chooseact);
String FullData = getIntent().getStringExtra("FullData");
try{
JSONObject obj = new JSONObject(FullData);
List<String> leagues = new ArrayList<String>();
JSONObject objData = obj.getJSONObject("data");
JSONArray jArray = objData.getJSONArray("structure");
for (int i=0; i < jArray.length(); i++) {
JSONObject oneObject = jArray.getJSONObject(i);
leagues.add(oneObject.getString("league_website_name"));
JSONArray DivisionsArray = oneObject.getJSONArray("divisions");
for (int d=0; d < DivisionsArray.length(); d++){
JSONObject DivDict = DivisionsArray.getJSONObject(d);
leagues.add(DivDict.getString("name"));
}
}
setListAdapter ( new ArrayAdapter<String>(this, R.layout.single_item,
leagues));
ListView list = getListView();
list.setTextFilterEnabled(true);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
回答by huntsfromshadow
A quick google of "android sectioned listview" will return results for example http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/
“android sectioned listview”的快速谷歌将返回结果,例如http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/
In fast summary though you end up writing a list adapter that returns a header layout when needed, and a row layout when needed.
总而言之,您最终会编写一个列表适配器,该适配器在需要时返回标题布局,并在需要时返回行布局。
回答by dwery
The correct answer is that section are not supported at all. You have to fake them.
正确答案是根本不支持该部分。你必须伪造它们。