我想添加一个“按钮”,该按钮会导致我的应用主要活动中的新活动。我无法通过此按钮来响应此主要活动。我试着将以下内容放在我当前的代码中:
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>
答案 0 :(得分:-1)
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text";
android:textSize="28sp" />