我使用RecyclerView
作为第一个标签页,ListView
表示其他标签页。
当我在RecyclerView
中向ListView
滚动时public class QuestionListAdapter extends RecyclerView.Adapter<QuestionListAdapter.CustomViewHolder> {
private List<QuestionListModel> feedItemList;
private Context mContext;
private String UserIDFromDatabase = "";
private ConnectionDetector connectionDetector;
public QuestionListAdapter(Context context, List<QuestionListModel> feedItemList, String UserIDFromDatabase) {
this.feedItemList = feedItemList;
this.mContext = context;
this.UserIDFromDatabase = UserIDFromDatabase;
connectionDetector = new ConnectionDetector(mContext);
}
@Override
public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.buds_profile_list_child, null);
CustomViewHolder viewHolder = new CustomViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(CustomViewHolder customViewHolder, int i) {
QuestionListModel feedItem = feedItemList.get(i);
// Setting text view title
customViewHolder.textView.setText(Html.fromHtml(feedItem.getQuestion()));
}
@Override
public int getItemCount() {
return (null != feedItemList ? feedItemList.size() : 0);
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
protected TextView textView;
public CustomViewHolder(View view) {
super(view);
this.textView = (TextView) view.findViewById(R.id.textView_ask_question_bplc);
}
}
。但是当我从第一个标签滑动到另一个标签并返回第一个标签时,我得到如下结果
第一次:
从其他标签旅行后:
public class QuestionFragment extends Fragment {
ConnectionDetector connectionDetector;
View rootView;
String UserIDFromDatabase = "";
int sendToServerOffsetPub = 0;
Boolean callSuccessful = false;
private RecyclerView mRecyclerView;
private QuestionListAdapter adapter;
private com.oi.example.swipyrefreshlayout.SwipyRefreshLayout swipeRefreshLayout;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.public__question_fragment, container, false);
initializeScreen();
return rootView;
}
private void initializeScreen() {
Utility.sp = getActivity().getSharedPreferences("User_Details", Context.MODE_PRIVATE);
UserIDFromDatabase = Utility.sp.getString("UserID", "");
// Initialize recycler view
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_public__question_paqf);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
adapter = new QuestionListAdapter(getActivity(), Utility.arrayListQuestionListModels, UserIDFromDatabase);
mRecyclerView.setAdapter(adapter);
connectionDetector = new ConnectionDetector(getActivity());
swipeRefreshLayout = (com.oi.example.swipyrefreshlayout.SwipyRefreshLayout) rootView.findViewById(R.id.swipe_refresh_public_listview_paqf);
swipeRefreshLayout.setColorSchemeResources(R.color.color_dark_grey);
swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(SwipyRefreshLayoutDirection direction) {
if (direction == SwipyRefreshLayoutDirection.BOTTOM) {
if (connectionDetector.isConnectingToInternet()) { // if 1
if ((Utility.publicCount > 0) && (Utility.arrayListQuestionListModels.size() > 0)) {
sendToServerOffsetPub++;
try {
callSuccessful = new getQuestionListOnProfile(getActivity(), Utility.referenceForProfileID, sendToServerOffsetPub, "PUBLIC").execute().get();
} catch (InterruptedException | ExecutionException e) {
callSuccessful = false;
}
if (!callSuccessful) {
adapter.notifyDataSetChanged();
}
// stopping swipe refresh
swipeRefreshLayout.setRefreshing(false);
} else {
// stopping swipe refresh
swipeRefreshLayout.setRefreshing(false);
}
} else {
Toast.makeText(getActivity(), Constants.INTERNET_CONNECTION, Toast.LENGTH_SHORT).show();
// stopping swipe refresh
swipeRefreshLayout.setRefreshing(false);
}
}
}
});
mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Utility.ID = (Utility.arrayListQuestionListModels.get(position).getId());
RateFeedController rateFeedController = new RateFeedController(getActivity());
ArrayList<HashMap<String, String>> DetailsArraylist = new ArrayList<HashMap<String, String>>();
DetailsArraylist = rateFeedController.getDetailsForSays(Utility.ID);
if (DetailsArraylist.size() > 0) {
String creatorID = DetailsArraylist.get(0).get("userID");
if (creatorID.equalsIgnoreCase(BudsProfileActivity.UserIDFromDatabase)) {
Utility.attachedListPPFM = 2;
}
Intent intentSays = new Intent(getActivity(), SaysScreenActivity.class);
intentSays.putExtra("ProfileBACKFLAG", "BudsProfileActivity");
startActivity(intentSays);
} else {
if (connectionDetector.isConnectingToInternet()) {// If 2
new GetFromServer(getActivity(), Integer.toString(Utility.ID), BudsProfileActivity.UserIDFromDatabase).execute();
} else {
Toast.makeText(getActivity(), Constants.INTERNET_CONNECTION, Toast.LENGTH_SHORT).show();
}// End of If 2
}
}
}));
}
}
}
片段:
bundle gem demo_gem
答案 0 :(得分:0)
不知道出了什么问题,但我只是删除了父版面SwipyRefreshLayout
,我的问题得到了解决 ..