2013-07-19 68 views
2
我在與轉換我的代碼進行分段

Google+的API活動,分片

這是我的代碼時,我的應用程序仍然是一個活動

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編程的新手

+0

需要延長的活動你FragmentActivity,需要添加此導入SupportFragment( \額外\機器人\ supporty \ V4 ......)< - 我不知道有關文件夾:S –

+0

發佈您的片段代碼.. –

+0

您使用靜態或動態片段?沒有代碼,我們所能做的只是猜測問題的可能原因。 – IanB

回答

3

事情的數量可能出了錯。一個問題是訪問你的childFragmentManager。經理不會將結果傳遞給片段,您必須在基類中手動執行該操作。

public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
     super.onActivityResult(requestCode, resultCode, intent); 
     Fragment fragment = (Fragment) getChildFragmentManager().findFragmentByTag(childTag); 
     if(fragment != null){ 
      fragment.onActivityResult(requestCode, resultCode, intent); 
     } 
}