以下是交易人员,我有一个包含2个片段的活动(我们称之为FragmentA
和FragmentB
)。 FragmentA
布局包含ListView
,FragmentB
布局的LinearLayout
包含3 ImageButtons
。
我想要做的是在滚动FragmentA' LinearLayout
时隐藏/制作隐藏的FragmentB ListView
。
这是我的ListFragment代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View body = inflater.inflate(R.layout.list_frag, container, false);
View button = inflater.inflate(R.layout.button_frag,container,false);
linear = (LinearLayout) button.findViewById(R.id.buttons)
myStuff = (ListView) body.findViewById(android.R.id.list);
myStuff.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScroll(AbsListView v, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
@Override
public void onScrollStateChanged(AbsListView v, int scrollState) {
switch(scrollState) {
case 2: // SCROLL_STATE_FLING
//hide button here
linear.setVisibility(View.GONE);
break;
case 1: // SCROLL_STATE_TOUCH_SCROLL
//hide button here
linear.setVisibility(View.GONE);
break;
case 0: // SCROLL_STATE_IDLE
//show button here
linear.setVisibility(View.VISIBLE);
break;
default:
//show button here
linear.setVisibility(View.VISIBLE);
break;
}
}
});
上面的代码不起作用,因为我对Fragments相当新,所以我遇到了障碍。你们知道我做错了什么吗?