Android如何传递Activity.class作为函数的参数 [英] Android how to pass an Activity.class as an argument for a function
本文介绍了Android如何传递Activity.class作为函数的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近从python转移到Android并且被困在这里。
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)
.setTitle(strTitle).setItems(strArray,
new DialogInterface.OnClickListener() {
@Override
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 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.
推荐答案
如果您只想传递对您的活动使用的引用: MakeCall .this
(或者只是这个
。)
If you just want to pass a reference to your Activity use: MakeCall.this
(or maybe just this
.)
这篇关于Android如何传递Activity.class作为函数的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文