我有一个问题,我的视图寻呼机在我按下时显示空白片段。 我有一个网格片段(考虑片段A),当我点击一个按钮时,它导航我到另一个网格片段(考虑片段B),当我点击一个按钮时,它导航我到一个有三个Slidingtabs的ViewPager(Fragment C) 。每个Tab布局都有一个列表视图,如果我选择一个项目,它会导航我到另一个片段(片段D)。我的问题是当我从片段D反印时,ViewPager滑动标签(片段C)显示空白的空白屏幕。任何人都可以告诉我如何解决这个问题。
public class RetrievalListOperation extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
List<VehicleInfo> vehicleInfos=new VehicleInfoData().getVehicleData();
DataService dataService;
List<VinInfoDTO> retlist;
private OnFragmentInteractionListener mListener;
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment RetrievalListOperation.
*/
// TODO: Rename and change types and number of parameters
public static RetrievalListOperation newInstance(String param1, String param2) {
RetrievalListOperation fragment = new RetrievalListOperation();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
public RetrievalListOperation() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_retrieval_list_operation, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
dataService=new DataService(getActivity());
retlist=dataService.getRetrievalJobsForStatus("Open");
super.onViewCreated(view, savedInstanceState);
RecyclerView rv = (RecyclerView) getActivity().findViewById(R.id.retrieval_operation_rview);
rv.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(getActivity().getApplicationContext());
rv.setLayoutManager(llm);
RetrievalOpenAdapter adapter=new RetrievalOpenAdapter(retlist);
rv.setAdapter(adapter);
rv.addOnItemTouchListener(
new RecycleItemClickListener(getActivity().getApplicationContext(), new RecycleItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
final TextView vin=(TextView)view.findViewById(R.id.ret_txt_VIN);
final TextView model=(TextView)view.findViewById(R.id.ret_txt_model);
final TextView variant=(TextView)view.findViewById(R.id.ret_txt_variant_no);
final TextView desc=(TextView)view.findViewById(R.id.ret_txt_description);
// final TextView color=(TextView)view.findViewById(R.id.ret_txt_color);
String VIN=vin.getText().toString();
Log.e("--Recycler onTouch VIN-", VIN);
JobsDTO det = dataService.getVehicleDetails(VIN);
String detail=det.JobID+" / SyncStatus: "+det.SyncStatus+" /Location Lat"+det.locationDTO.Latitude+" lng"+det.locationDTO.Longitude;
Log.e("---RetoPenList---", detail);
Bundle b=new Bundle();
b.putString("VIN", VIN);
b.putString("model", model.getText().toString());
b.putString("variant", variant.getText().toString());
b.putString("desc",desc.getText().toString());
// b.putString("color",color.getText().toString());
b.putString("job id",det.JobID);
Log.e("---Bundle Values--", " MODEL: " + model.getText().toString() + " VARIANT :" + variant.getText().toString() + " DESC:" + desc.getText().toString() + " COLOR :" );
Fragment fragment=new RetrievalMapOperation().newInstance("a" ," b");
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment).addToBackStack("RetrievalList")
.commit();
fragment.setArguments(b);
}
})
);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(Uri uri);
}
public class RetrievalOpenAdapter extends RecyclerView.Adapter<RetrievalOpenAdapter.ViewHolder>
{
List<VinInfoDTO> vinfo;
RetrievalOpenAdapter(List<VinInfoDTO> vinfo)
{
this.vinfo=vinfo;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.operationscardlayout, parent, false);
ViewHolder pvh = new ViewHolder(v);
return pvh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.vehicleNumber.setText(vinfo.get(position).VIN);
holder.variantNumber.setText(vinfo.get(position).Variant);
// holder.color.setText(vinfo.get(position).Color);
holder.desc.setText(vinfo.get(position).Desc);
holder.model.setText(vinfo.get(position).Model);
// Log.e("--RetCOLOR--",""+holder.color.getText().toString());
// holder.time.setText(vinfo.get(position).getTime());
}
@Override
public int getItemCount() {
return vinfo.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
CardView cv;
TextView vehicleNumber;
TextView variantNumber;
TextView model,color,desc ;
public ViewHolder(View itemView) {
super(itemView);
cv=(CardView)itemView.findViewById(R.id.operation_retrieval_cview);
vehicleNumber=(TextView)itemView.findViewById(R.id.ret_txt_VIN);
variantNumber=(TextView)itemView.findViewById(R.id.ret_txt_variant_no);
model=(TextView)itemView.findViewById(R.id.ret_txt_model);
// color= (TextView)itemView.findViewById(R.id.ret_txt_color);
desc=(TextView)itemView.findViewById(R.id.ret_txt_description);
//time=(TextView)itemView.findViewById(R.id.txt_srtime);
}
}
}
}
RetrievalTabs.java (slidinglayout)
public class RetrievalTabs extends Fragment {
NavigationDrawerActivity nav;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
CharSequence Titles[] = {"Open", "WIP", "Complete"};
int Numboftabs = 3;
ViewPager pager;
FrameLayout frameLayout;
LinearLayout linear;
private TextView actionBarTitle;
SlidingTabLayout tabs;
RetrievalPagerAdapter adapter;
private OnFragmentInteractionListener mListener;
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment RetrievalTabs.
*/
// TODO: Rename and change types and number of parameters
public static RetrievalTabs newInstance(String param1, String param2) {
RetrievalTabs fragment = new RetrievalTabs();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
public RetrievalTabs() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
View actionBarCustomView = getActivity().getActionBar().getCustomView();
actionBarTitle = (TextView) actionBarCustomView.findViewById(R.id.head_text);
actionBarTitle.setText("Retrieval");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_retrieval_tabs, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
tabs = (SlidingTabLayout) getActivity().findViewById(R.id.retrieval_tabs);
adapter = new RetrievalPagerAdapter(getFragmentManager(), Titles, Numboftabs);
pager = (ViewPager) getActivity().findViewById(R.id.retrieval_pager);
pager.setAdapter(adapter);
tabs.setDistributeEvenly(true);
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
tabs.setViewPager(pager);
}
});
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(Uri uri);
}
}
RetrievalPagerAdapter.java
public class RetrievalPagerAdapter extends android.support.v13.app.FragmentStatePagerAdapter {
CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created
android.app.Fragment tab1, tab2, tab3;
FragmentManager fm;
MyApplication app;
public RetrievalPagerAdapter(FragmentManager fm, CharSequence mTitles[], int NumOfTabs) {
super(fm);
this.fm = fm;
this.Titles = mTitles;
this.NumbOfTabs = NumOfTabs;
}
@Override
public CharSequence getPageTitle(int position) {
return Titles[position];
}
@Override
public int getCount() {
return NumbOfTabs;
}
@Override
public android.app.Fragment getItem(int position) {
if (position == 0) {
tab1 = new RetrievalListOperation().newInstance("a", "b");
return tab1;
} else if (position == 1) {
tab2 = new RetrievalInProgressList().newInstance("a", " b");
return tab2;
} else {
tab3 = new RetrievalCompletedList().newInstance("a", "b");
return tab3;
}
}
public int getItemPosition (Object object)
{
return POSITION_NONE;
}
}