java - Facebook 点赞按钮的说明

标签 java android facebook

我遇到以下问题。我正在尝试为我的 Facebook 页面创建一个“赞”按钮,但我卡住了。我按照说明进行操作,但它不起作用!我没有看到设置此按钮坐标的值。它在哪里?谢谢

EDIT2:我又编辑了一下,现在第一个onActivityResult有这个问题:

void 是变量 onActivityresult 的无效类型

出了什么问题?

主要 Activity :

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import ch.OptiLab.visuscontroll.R;

import com.facebook.UiLifecycleHelper;
import com.facebook.widget.LikeView;


public class MainActivity extends Activity implements OnClickListener {




//UiLifecycleHelper uiHelper;
TextView textView;
//  Button buttonende;
    Button tipps;
        Button btn1;
        Button rate;

    LikeView LikeView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

      textView = (TextView) findViewById(R.id.textView);
      tipps = (Button) findViewById(R.id.tipps);
        btn1 = (Button) findViewById(R.id.buttonSTART);
        btn1.setOnClickListener(this);
        rate = (Button) findViewById(R.id.rate);
        rate.setOnClickListener(this);
        AppRater.app_launched(this);

        Settings.sdkInitialize(this);
        LikeView = (LikeView) findViewById(R.id.LikeView);
        LikeView.setObjectId("http://shareitexampleapp.parseapp.com/photo1/");


       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);

         likeView.handleOnActivityResult(this, requestCode, resultCode, data);

        }



 tipps.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View v) {


            // 1. Instantiate an AlertDialog.Builder with its constructor
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

            // 2. Chain together various setter methods to set the dialog characteristics
            builder.setMessage(R.string.dialog_message)
                   .setTitle(R.string.dialog_title);

            // 3. Get the AlertDialog from create()
            AlertDialog dialog = builder.create();
            dialog.show();
        }




       });
    }

    protected Context getActivity() {

        return null;
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) { 
            Toast.makeText(getApplicationContext(), "Easteregg lololol", Toast.LENGTH_LONG).show();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public void onClick(View v) {

        startActivityForResult(new Intent(this,VisusActivity.class), 0);

    }







    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == R.drawable.v1)textView.setText(getResources().getString(R.string.nopercent));
        else if (resultCode == R.drawable.v2)textView.setText(getResources().getString(R.string.tenpercent));
        else if (resultCode == R.drawable.v3)textView.setText(getResources().getString(R.string.twentypercent));
        else if (resultCode == R.drawable.v4)textView.setText(getResources().getString(R.string.thirtypercent));
        else if (resultCode == R.drawable.v5)textView.setText(getResources().getString(R.string.fourtypercent));
        else if (resultCode == R.drawable.v6)textView.setText(getResources().getString(R.string.fiftypercent));
        else if (resultCode == R.drawable.v7)textView.setText(getResources().getString(R.string.sixtypercent));
        else if (resultCode == R.drawable.v8)textView.setText(getResources().getString(R.string.seventypercent));
        else if (resultCode == R.drawable.v9)textView.setText(getResources().getString(R.string.eightypercent));
        else if (resultCode == R.drawable.v10)textView.setText(getResources().getString(R.string.ninetypercent));
        else if (resultCode == R.drawable.v11)textView.setText(getResources().getString(R.string.onehundretpercent));



    }   
    @Override
    protected void onResume() {
      super.onResume();

      // Logs 'install' and 'app activate' App Events.

    }

xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="ch.OptiLab.visustest.MainActivity" >



<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:gravity="center_horizontal"
    android:singleLine="false"
    android:text="@string/Text1"
    android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/buttonSTART"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="@string/button1"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="142dp" />

    <Button
        android:id="@+id/buttonende"
        android:layout_width="180dp"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/textView"
        android:layout_marginBottom="14dp"
        android:text="@string/beenden" />

    <Button
        android:id="@+id/tipps"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/buttonSTART"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="52dp"
        android:text="@string/tipps_tricks" />

    <com.facebook.widget.LikeView
 android:id="@+id/LikeView"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/tipps"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="29dp" >

</RelativeLayout>

最佳答案

void 是变量 onActivityresult 的无效类型,因为您在 onCreate 方法中使用了 onActivityresult 方法。从 onCreate 中删除此方法并调用

likeView.handleOnActivityResult(this, requestCode, resultCode, data);

来自您的 onActivityResult 方法。另请检查您的 LikeView 变量名称,它在您使用的任何地方都应该相同。

关于java - Facebook 点赞按钮的说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26852071/

相关文章:

ruby-on-rails - 使用 devise + omniauth + rails 3 时如何清除 facebook session 和 cookie?

javascript - 从父窗口(facebook oAuth 生成)重定向时获取子窗口的 url

Java 应用程序作为系统服务

java - 在 J2EE 应用程序中,什么时候调用监听器?

java - 具有 2 个工厂方法的抽象工厂模式

java - 如何验证重构等于原始代码

android - Droid X 未连接到 OS X 上的 adb

具有垂直分页的android pdf查看器

android - 如何使用 Phonegap Build 设置 Android 权限?

javascript - 如果我在 IE 9 中刷新页面,Facebook 登录按钮就会消失