0

MainActivity [A]

    public class ViewActivity extends AppCompatActivity implements
        FilterDialogFragment.FilterListener,
        AffichageAdapter.OnAffichageSelectedListener {

   public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_view);
           ButterKnife.bind(this);

Class [B]: i want to create a AlertDialogue when i click that its show in ViewActivity

public class AffichageAdapter extends FirestoreAdapter<AffichageAdapter.ViewHolder> {

AlertDialog.Builder Alert = new AlertDialog.Builder(What i Put here ! );
Halas
  • 19
  • 7
  • https://stackoverflow.com/questions/49492474/how-to-use-get-getapplicationcontext-in-adapter-class/49492494#49492494 – AskNilesh Sep 19 '18 at 03:50

3 Answers3

1

YourClassName.this or getContext()

Rubick
  • 296
  • 3
  • 22
0

If you are trying to show alert from a different class in MainActivity A. You should pass getContext() parameter from MainActivity to that Class B's show alert function.

Min Khant Lu
  • 712
  • 1
  • 9
  • 20
  • when i create a method to get Context and i call it in second class that write " No static" and when i turn getContext to ( public static context ) that write cannot referenced from static method – Halas Sep 19 '18 at 03:23
0

In AffichageAdapter class , you could declare a field like this:

private Context mContext;

public AffichageAdapter(Context context){
      this.mContext = context;//get context by constructor
}

and in ViewActivity

AffichageAdapter adapter = new AffichageAdapter(this);//"this" means ViewActivity, its a context.
xxx.setAdapter(adapter); // in some place.

then:

AlertDialog.Builder Alert = new AlertDialog.Builder(mContext);
navylover
  • 12,383
  • 5
  • 28
  • 41