亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

第一項活動僅適用于我的 Android 項目

第一項活動僅適用于我的 Android 項目

慕森王 2022-10-07 17:28:03
我是 android 和 java 編程的新手,所以我嘗試從幾個項目中學習,但我遇到了這個問題。當我嘗試運行應用程序時,只有第一個活動在工作,而第二個活動不工作。我在哪里錯過了這個應用程序?我很困惑,兩個 java 項目正在運行,但唯一的第一個活動有效。activity_main.xml<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.android_examples.wallpaper_android_examplescom.MainActivity">    <ImageView        android:id="@+id/imageView"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:src="@drawable/img76"        android:layout_above="@+id/btn_right"        android:layout_alignParentTop="true"        android:layout_marginBottom="30dp"        android:scaleType="fitXY" />    <Button        android:id="@+id/btn_right"        style="@style/Widget.AppCompat.Button.Colored"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignBaseline="@+id/btn_left"        android:layout_alignBottom="@+id/btn_left"        android:layout_alignParentEnd="true"        android:layout_alignParentRight="true"        android:layout_marginEnd="42dp"        android:layout_marginRight="42dp"        android:text="RIGHT" />    <Button        android:id="@+id/btn_left"        style="@style/Widget.AppCompat.Button.Colored"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentStart="true"        android:layout_alignParentLeft="true"        android:layout_alignParentBottom="true"        android:layout_marginStart="43dp"        android:layout_marginLeft="43dp"        android:layout_marginBottom="100dp"        android:text="LEFT" /></RelativeLayout>
查看完整描述

5 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

在您的點擊偵聽器中編寫此代碼:


  btn_right.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View v) {

            current_image_index++;

            current_image_index = current_image_index % images.length;

            imageView.setImageResource(images[current_image_index]);


            Intent intent = new Intent(this, MainActivity.class);

            startActivity(intent);

        }

    });


查看完整回答
反對 回復 2022-10-07
?
紅糖糍粑

TA貢獻1815條經驗 獲得超6個贊

你必須開始你的第二個活動

startActivity(new Intent(getApplicationContext(), MainActivity.class));

確保您在清單文件中添加了第二個活動


查看完整回答
反對 回復 2022-10-07
?
catspeake

TA貢獻1111條經驗 獲得超0個贊

沒有代碼可以導航到 MainActivity


觸發以下代碼


private void startMainActivity(){

     Intent intent = new Intent(this, MainActivity.class);

     startActivity(intent);

}


查看完整回答
反對 回復 2022-10-07
?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

 void SwitchButton() {

    btn_right = (Button) findViewById(R.id.btn_right);

    btn_left = (Button) findViewById(R.id.btn_left);

    btn_right.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View v) {

            current_image_index++;

            current_image_index = current_image_index % images.length;

            imageView.setImageResource(images[current_image_index]);

            startMainPage();

        }

    });


    btn_left.setOnClickListener(new View.OnClickListener() {

                                    @Override

                                    public void onClick(View v) {

                                        current_image_index--;


                                        if (current_image_index < 0) {

                                            current_image_index = images.length - 1;

                                        }

                                        imageView.setImageResource(images[current_image_index]);

                                        startMainPage();

                                    }

                                }



    );



}


private void startMainPage() {

    Intent intent = new Intent(Login.this, MainActivity.class);

    startActivity(intent);

}


查看完整回答
反對 回復 2022-10-07
?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

無論您想在哪里調用下一個活動,請使用:-


  Intent intent = new Intent(this, MainActivity.class);

  startActivity(intent);


查看完整回答
反對 回復 2022-10-07
  • 5 回答
  • 0 關注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號