2016-04-06 3 views
0

をadapterview.onitemclicklistenerに適用することができない私はエラーを取得する:エラーコンテキストが

getFacebookPageURL (android.content.Context) cannot be applied to (android.widget.AdapterView.OnItemClickListener) with this

は、ここに私のコードです:

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);  
+1

"Activiy.this"ではなく "this"を試してください – Sanoop

+0

私の答えはあなたの問題を解決しましたか? –

答えて

0

は次のように試してみてくださいこれは:

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.OnItemClickListenerContextを拡張しません。