我想用second_main.XML进行新的活动,通过使用2个按钮导致activity_main

时间:2018-06-10 19:25:15

标签: java android xml

我正在使用Android应用程序进行图像分割。我想使用 second_main.XML 进行新活动,其中有2个按钮可以打开,并通过按钮点击导致 activity_main.XML ,但问题是只有activity_main被打开。

这是我的代码:

MainActivity.java

public class MainActivity extends ActionBarFragmentActivity {

private final static int REQUEST_REQUIRED_PERMISSION = 0x01;
private final static int REQUEST_PICK_IMAGE = 0x02;


private class InitializeModelAsyncTask extends AsyncTask<Void, Void, Boolean> {

    @Override
    protected Boolean doInBackground(Void... voids) {
        final boolean ret = DeeplabModel.initialize();
        final boolean ret2= DeeplabModel2.initialize();
        Logger.debug("initialize deeplab model: %s", ret);
        Logger.debug("initialize deeplab model: %s", ret2);
        if( ret){
            return ret;
        }else {
            return ret2;
        }

    }

}

private FloatingActionButton mFabPickImage;

static final int REQUEST_IMAGE_CAPTURE=1;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    setupViews();
}

}

MainSecond.java

public  class MainSecond extends Activity {
public Button button1;
public Button button2;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second_main);


    button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            BackToMain(view);

        }
    });

    button2 = (Button) findViewById(R.id.button2);
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            BackToMain(view);
        }

    });
}

public void BackToMain(View view) {
    Intent intent = new Intent(this, MainSecond.class);
    startActivity(intent);

}

activity_main.xml中

  <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/src_img"
        android:scaleType="centerInside"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp" />

    <ImageView
        android:id="@+id/segment_img"
        android:scaleType="fitCenter"
        android:tint="@color/colorAccent"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp" />

    <ImageView
        android:id="@+id/cropped_img"
        android:scaleType="fitCenter"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp" />

</LinearLayout>-->

<fragment
    android:id="@+id/fragment_segment_bitmaps"
    android:name="com.dailystudio.deeplab.SegmentBitmapsFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_pick_image"
    android:layout_width="53dp"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_marginBottom="@dimen/fab_mini_margin_v"
    android:layout_marginEnd="@dimen/fab_margin"
    android:enabled="false"
    android:src="@drawable/ic_action_pick_image"
    tools:layout_editor_absoluteX="334dp" />

<Button
    android:id="@+id/buckysButton"
    android:layout_width="170dp"
    android:layout_height="91dp"
    android:onClick="launchCamera"
    android:text="Take Photo"
    tools:ignore="OnClick"
    tools:layout_editor_absoluteX="700dp"
    tools:layout_editor_absoluteY="700dp"
    />

MainSecond.java

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="52dp"
    android:text="choose the type of photo"
    android:textSize="30sp"
    tools:layout_width="match_parent" />

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_centerVertical="true"
    android:elevation="90dp"
    android:text="Indoors"
    tools:layout_height="60dp"
    tools:layout_width="400dp" />

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/button1"
    android:layout_marginTop="19dp"
    android:text="Outdoors"
    tools:layout_height="60dp" />

0 个答案:

没有答案