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編程的新手
需要延長的活動你FragmentActivity,需要添加此導入SupportFragment( \額外\機器人\ supporty \ V4 ......)< - 我不知道有關文件夾:S –
發佈您的片段代碼.. –
您使用靜態或動態片段?沒有代碼,我們所能做的只是猜測問題的可能原因。 – IanB