-4
我想添加一個'按鈕',導致我的應用程序的主要活動內的新活動。我無法獲得這個按鈕來回應這個主要活動。我試圖把下面我當前的代碼:如何添加按鈕去Android應用程序中的新活動
public class MainActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {
private ImageView photoImageView;
private TextView nameTextView;
private TextView emailTextView;
private TextView idTextView;
private GoogleApiClient googleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
photoImageView = (ImageView) findViewById(R.id.photoImageView);
nameTextView = (TextView) findViewById(R.id.nameTextView);
emailTextView = (TextView) findViewById(R.id.emailTextView);
idTextView = (TextView) findViewById(R.id.idTextView);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
googleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
// I want something like this - click a textView to go to the new activity
TextView listViewItem = (TextView) findViewById(R.id.textView11);
listViewItem.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
}
// end
@Override
protected void onStart() {
super.onStart();
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(googleApiClient);
if (opr.isDone()) {
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
handleSignInResult(googleSignInResult);
}
});
}
}
我怎樣才能得到這個按鈕轉到我的新活動?我目前使用文本視圖作爲按鈕。這是我的問題嗎?
<LinearLayout
<TextView
android:id="@+id/textView11"
android:text="One"
tools:layout_editor_absoluteY="70dp" />
</LinearLayout>
其中是按鈕??把你的xml代碼和圖像 –
我編輯併發布了我的xml的重要位@VishvaDave – guesswho
是否有任何錯誤日誌?這個textview是在activity_main.xml裏面的嗎? –