Kalanamith Kalanamith - 11 months ago 31
Android Question

Android how to pass an Activity.class as an argument for a function

I recently moved to Android from python and am stuck here.

This is my class declaration to create a common function for an Alert Dialog which accepts necessary parameters

public static AlertDialog.Builder getAlertDialog(String strArray[],
String strTitle, Activity v) {

return new AlertDialog.Builder(v)
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

But I cannot call this function via this piece of code which gives me an error

getAlertDialog(strArray, strTitle, MakeCall.class).show();

The error is

the method getAlertDialog(String[], String, Activity) in the type MakeCallAlertDialog is not applicable for the arguments (String[], String, Class<TestActivity>)

Can anyone tell me how to get this correctly? Thank you in advance.

Sam Sam

If you just want to pass a reference to your Activity use: MakeCall.this (or maybe just this.)