我有以下问题。我正在尝试为我的Facebook页面创建一个类似的按钮,但我卡住了。我按照说明操作但是没有用!我无处可看到设置此按钮坐标的值。它在哪里?谢谢
EDIT2:我再次编辑它,现在,第一个onActivityResult有这个问题:
void是onActivityresult变量的无效类型
出了什么问题?
主要活动:
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>
答案 0 :(得分:1)
void是变量onActivityresult
发生的无效类型,因为您在onActivityresult
方法中使用onCreate
方法。从onCreate中删除此方法并调用
likeView.handleOnActivityResult(this,requestCode,resultCode,data);
来自onActivityResult
方法。还要检查你的LikeView变量名称,它应该在你使用的任何地方都一样。
答案 1 :(得分:0)
我遇到了实施LikeView的问题,直到我将Facebook API从3.18升级到3.20。
此外,您不能使用常规按钮。你需要像这样使用Facebook LikeView小部件:
<com.facebook.widget.LikeView
android:id="@+id/lvLike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>