2

コードをフラグメントに変換するのに問題があります

これは私のアプリがまだアクティビティであるときの私のコードです

package com.ronnielp.loginsample2;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.plus.PlusClient;
import com.google.android.gms.plus.model.people.Person;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class SignIn extends Activity implements OnClickListener, 
    ConnectionCallbacks, OnConnectionFailedListener{


    private static final int REQUEST_CODE_RESOLVE_ERR = 40;
    private PlusClient mPlusClient;
    private ConnectionResult mConnectionResult;
    private TextView txtUser;

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

        mPlusClient =new PlusClient.Builder(this, this, this)
        .setScopes(Scopes.PLUS_LOGIN)
        .setVisibleActivities("http://schemas.google.com/AddActivity")
        .build();

        findViewById(R.id.sign_in_button).setOnClickListener(this);
        txtUser = (TextView) findViewById(R.id.txtUser);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }



    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        mPlusClient.connect();
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        mPlusClient.disconnect();
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        // TODO Auto-generated method stub
        mConnectionResult = result;
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        // TODO Auto-generated method stub
        Person user = mPlusClient.getCurrentPerson();
        String acc = mPlusClient.getAccountName();
        txtUser.setText(acc);
    }

    @Override
    public void onDisconnected() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        if (view.getId() == R.id.sign_in_button &&  !mPlusClient.isConnected() && mConnectionResult !=null){
            try{
                mConnectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
            } catch (SendIntentException e){
                mConnectionResult = null;
                mPlusClient.connect();
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (requestCode == REQUEST_CODE_RESOLVE_ERR && resultCode == RESULT_OK){
            mConnectionResult = null;
            mPlusClient.connect();
        }
    }


}

それをフラグメントに変換すると、コードが機能しなくなります助けてください私はまだAndroidプログラミングの初心者です

4

1 に答える 1