-1
私はページャーの中でデータを表示する2つのフラグメントを扱っています。私の問題は、 2つの断片のうちの1つにmがあり、その両方の内容が空である場合、2つのダイアログが表示されます。 私はいくつかの方法を試みましたが、どれも私のために働いていませんでした。ここ私はページャー内でrecyclerviewが空のときにダイアログを表示します。android
は私のページャアダプタです:フラグメントの両方が類似している
public class PagerAdapter extends FragmentStatePagerAdapter {
ArrayList<Fragment> pages = new ArrayList<>();
public PagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return pages.get(position);
}
@Override
public int getCount() {
return pages.size();
}
@Override
public CharSequence getPageTitle(int position) {
return pages.get(position).toString();
}
public void addPage (Fragment f){
pages.add(f);
}
}
ので、私はそれらのいずれかのコードを紹介します:
public class FragmentIng extends Fragment {
private View v;
public FragmentIng() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
v = inflater.inflate(R.layout.fragment_ing, null);
RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.recyclerview);
Recycler_View_Adapter adapter = new Recycler_View_Adapter(personnes1, this.getActivity());
recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
recyclerView.setAdapter(adapter);
RecyclerView.ItemAnimator itemAnimator = new DefaultItemAnimator();
itemAnimator.setAddDuration(1000);
itemAnimator.setRemoveDuration(1000);
recyclerView.setItemAnimator(itemAnimator);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
int i = adapter.getItemCount();
if (i == 0 ){
final NiftyDialogBuilder dialogBuilder= NiftyDialogBuilder.getInstance(this.getContext());
dialogBuilder
.withTitle("Employé") //.withTitle(null) no title
.withTitleColor("#FFFFFF") //def
.withDividerColor("#11000000") //def
.withMessage("Aucun employé à afficher") //.withMessage(null) no Msg
.withMessageColor("#FFFFFFFF") //def | withMessageColor(int resid)
.withDialogColor("#FFE74C3C") //def | withDialogColor(int resid)
.withIcon(getResources().getDrawable(R.drawable.icon))
.withDuration(700) //def
.withEffect(Shake) //def Effectstype.Slidetop
.withButton1Text("Retour") //def gone
.withButton2Text("Annuler") //def gone
.isCancelableOnTouchOutside(true) //def | isCancelable(true)
//.setCustomView(R.layout.custom_view,v.getContext()) //.setCustomView(View or ResId,context)
.setButton1Click(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialogBuilder.cancel();
Toast.makeText(v.getContext(), "Principale", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getActivity(), MainActivity.class);
getActivity().startActivity(intent);
}
})
.setButton2Click(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(v.getContext(),"i'm btn2",Toast.LENGTH_SHORT).show();
dialogBuilder.cancel();
}
})
.show();
}
return v;
}
@Override
public String toString() {
return "Les Employés";
}
}
を、これが私のrecyclerviewアダプタです:
public class Recycler_View_Adapter extends RecyclerView.Adapter<View_Holder>{
List<Personne> personnes = Collections.emptyList();
Context context;
Dialog dialog;
public Recycler_View_Adapter(List<Personne> list, Context context) {
this.personnes = list;
this.context = context;
}
private Context getContext() {
return context;
}
@Override
public View_Holder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.row_layout, parent, false);
View_Holder holder = new View_Holder(v);
return holder;
}
@Override
public void onBindViewHolder(View_Holder holder, final int position) {
holder.title.setText(personnes.get(position).nom_prenom);
//holder.description.setText("Etage N° : "+personnes.get(position).etage+" à "+personnes.get(position).date.toDateTime());
holder.occurence.setText(personnes.get(position).occurence+"/"+personnes.get(position).NbrDeJour);
animate(holder);
}
@Override
public int getItemCount() {
return personnes.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public void animate(RecyclerView.ViewHolder viewHolder) {
final Animation animAnticipateOvershoot = AnimationUtils.loadAnimation(context, R.anim.bounce_interpolator);
viewHolder.itemView.setAnimation(animAnticipateOvershoot);
}
}
例えば
は、それが本当に私の問題を解決した、youuありがとうございました^^ – DevRj