Не удается показать BottomSheetDialogFragment от адаптера в Android? - PullRequest
0 голосов
/ 06 октября 2019

Фрагмент нижнего листа состоит из просмотра переработчика, и он всегда открывается, когда я запускаю приложение.

Это кнопка, с которой я запускаю фрагмент, если требуется какая-либо другая информация, я с радостью сообщаю спасибо. Вы.

      public profiles_adapter(Context context, int resourceId, ArrayList<profiles> profiles) {
    super(context, resourceId, profiles);
    this.context = context;
}

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    profiles profile = getItem(position);
    //image stuff
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.cards, parent, false);
    }
    ViewPagerAdapter viewPagerAdapter;
    ViewPager userImageViewPager;
    userImageViewPager = convertView.findViewById(R.id.userImageViewPager);

    String[] imageUrls = new String[]{};
    if (profile.getImages() != null) {
        imageUrls = profile.getImages();
        viewPagerAdapter = new ViewPagerAdapter(context, imageUrls);
        userImageViewPager.setAdapter(viewPagerAdapter);

    }



    more_info.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bundle data = new Bundle();//create bundle instance
            data.putString("profile_id", profile.getProfile_id());//put string to pass with a key value
            user_details ud = new user_details();
            ud.setArguments(data);//Set bundle data to fragment
            ud.show( ((FragmentActivity)context).getSupportFragmentManager(),"tagg");

        }
    });

1 Ответ

0 голосов
/ 06 октября 2019

Вы можете передать свою активность, а не context, поэтому будет показан BottomSheet.
Или я предлагаю создать интерфейс, чтобы адаптер мог взаимодействовать с ним (Activity / Fragment).

private ClickListener clickListener;
 public profiles_adapter(Context context, int resourceId, ArrayList<profiles> profiles,ClickListener clickListener) {
    super(context, resourceId, profiles);
    this.context = context;
    this.clickListener = clickListener;
}

public interface ClickListener{
    void onClickMoreInfo(String profileId);
}

теперь на вашем прослушивателе кликов:

 more_info.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
       clickListener.onClickMoreInfo(profile.getProfile_id());
         }
    });

И давайте предположим, что у вас есть такие же в вашем (Упражнение / Фрагмент)

profiles_adapter adapter = new profiles_adapter(context,id,list,this);

теперь заставьте ваш (Activity / Fragment) реализовать ваш интерфейс

implements ClickListener

и, наконец,

@Override
public void onClickMoreInfo(String profileId){
    Bundle data = new Bundle();//create bundle instance
    data.putString("profile_id", profile.getProfile_id());//put string to pass with a key value
    user_details ud = new user_details();
    ud.setArguments(data);//Set bundle data to fragment
 /*for activity*/   ud.show(getSupportFragmentManager(),"tagg");
  /*for fragment*/  ud.show(getActivity().getSupportFragmentManager(),"tagg");
}
...