gpt4 book ai didi

java - 带 ExpandableList 的 PullToRefresh 布局

转载 作者:行者123 更新时间:2023-12-01 14:58:30 25 4
gpt4 key购买 nike

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<com.handmark.pulltorefresh.library.PullToRefreshScrollView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ExpandableListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/black" />

<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No items"
android:textColor="@color/White" />

</com.handmark.pulltorefresh.library.PullToRefreshScrollView>

</LinearLayout>

这是我的 XML 布局文件,我正在使用 chrisbanes pull 来刷新库 here

出于某种原因,它只会显示可点击项目的可展开列表中的第一个,当我单击它时,它不会展开该行,我一直在研究这个问题,并且对为什么会发生这种情况感到困惑,这是 Fragment 类的代码

public class TestExpandFragment extends ExpandableListFragment {

private String[] divideOptions = { "Test1", "Test2", "Test3", "Test4",
"Test5", "Test6", "Test7", "Test8" };

PullToRefreshScrollView mPullRefreshScrollView;
ScrollView mScrollView;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment

try {

SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
getActivity(), createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "1" }, // the
// key
// of
// group
// item.
new int[] { R.id.row_name }, // ID of each group item.-Data
// under the key goes into
// this TextView.
createChildList(), // childData describes second-level
// entries.
R.layout.group_child_row, // Layout for sub-level
// entries(second
// level).
new String[] { "Sub Item" }, // Keys in childData maps to
// display.
new int[] { R.id.grp_child } // Data under the keys above go
// into these TextViews.
);
setListAdapter(expListAdapter); // setting the adapter in the list.

} catch (Exception e) {
System.out.println("Errrr +++ " + e.getMessage());
}

View view = inflater.inflate(R.layout.test_expandable_fragment, container,
false);

/** Implement Pull To Refresh **/
mPullRefreshScrollView = (PullToRefreshScrollView) view
.findViewById(R.id.pull_refresh_scrollview);
mPullRefreshScrollView
.setOnRefreshListener(new OnRefreshListener<ScrollView>() {

@Override
public void onRefresh(
PullToRefreshBase<ScrollView> refreshView) {

new GetDataTask().execute();

}

});

mScrollView = mPullRefreshScrollView.getRefreshableView();

return view;
}

/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
for (int i = 0; i < 8; ++i) { // 8 groups........
HashMap m = new HashMap();
m.put("1", divideOptions[i]); // the key and it's value.
result.add(m);
}
return (List) result;
}

/* creatin the HashMap for the children */
@SuppressWarnings("unchecked")
private List createChildList() {

ArrayList result = new ArrayList();
for (int i = 0; i < 15; ++i) { // this -15 is the number of groups(Here
// it's fifteen)
/*
* each group need each HashMap-Here for each group we have 3
* subgroups
*/
ArrayList secList = new ArrayList();
for (int n = 0; n < 3; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "Sub Item " + n);
secList.add(child);
}
result.add(secList);
}
return result;
}

public void onContentChanged() {
System.out.println("onContentChanged");
super.onContentChanged();
}

/* This function is called on each child click */
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
System.out
.println("Inside onChildClick at groupPosition = "
+ groupPosition + " Child clicked at position "
+ childPosition);
return true;
}

/* This function is called on expansion of the group */
public void onGroupExpand(int groupPosition) {
try {
System.out.println("Group exapanding Listener => groupPosition = "
+ groupPosition);
} catch (Exception e) {
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}

/** Sleeper for the PullToRefresh **/
private class GetDataTask extends AsyncTask<Void, Void, String[]> {

@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
return null;
}

@Override
protected void onPostExecute(String[] result) {
// Do some stuff here

// Call onRefreshComplete when the list has been refreshed.
mPullRefreshScrollView.onRefreshComplete();

super.onPostExecute(result);
}
}

}

如果有人可以告诉我为什么会发生这种情况,因为它只会输出 Test1 但没有任何操作,刷新拉动将在加载时出现,如果我取消刷新拉动,它确实有效,并且我之前曾在其他代码中围绕其他类型的布局使用过它,但从未遇到过这种情况,也许这很愚蠢,我不确定,但我想也许有人可以更快地看到问题。

最佳答案

我从未使用过该库,但一般来说,您不能将 ListView 放入 ScrollView 中(想一想)。看着library classes不过,您应该尝试改用 PullToRefreshExpandableListView

关于java - 带 ExpandableList 的 PullToRefresh 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14015487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com