![](/img/trans.png)
[英]OnItemClickListener Cannot instantiate the type AdapterView.OnItemClickListener
[英]error context cannot be applied to adapterview.onitemclicklistener
我得到錯誤:
使用此方法無法將getFacebookPageURL(android.content.Context)應用於(android.widget.AdapterView.OnItemClickListener)
這是我的代碼:
public static String FACEBOOK_URL = "https://www.facebook.com/YourPageName";
public static String FACEBOOK_PAGE_ID = "YourPageName";
//method to get the right URL to use in the intent
public String getFacebookPageURL(Context context) {
PackageManager packageManager = context.getPackageManager();
try {
int versionCode = packageManager.getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) { //newer versions of fb app
return "fb://facewebmodal/f?href=" + FACEBOOK_URL;
} else { //older versions of fb app
return "fb://page/" + FACEBOOK_PAGE_ID;
}
} catch (PackageManager.NameNotFoundException e) {
return FACEBOOK_URL; //normal web url
}
}
然后按如下所示啟動意圖:
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(this);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);
嘗試這樣:
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getFacebookPageURL(MainActivity.this); //name of your activity
facebookIntent.setData(Uri.parse(facebookUrl));
MainActivity.this.startActivity(facebookIntent);
由於只是this
指的是AdapterView.OnItemClickListener
不Activity
類。 而且AdapterView.OnItemClickListener
不會擴展Context
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.