Вот код MainActivity. Я новичок ie, и я хотел бы услышать, что вы, ребята, должны сказать. Я застрял на этом в течение достаточно долгого времени. Я пытаюсь создать многоэкранное приложение, и если я закомментирую функциональность кнопок, то файл xml для моей основной деятельности будет работать отлично. Я новичок и не знаю, что не так с кодом.
'' '
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
Button list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View view = this.getWindow().getDecorView();
list=(Button) findViewById(R.id.list);
list.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
// Intents are objects of the android.content.Intent type. Your code can send them
// to the Android system defining the components you are targeting.
// Intent to start an activity called SecondActivity with the following code:
Intent intent = new Intent(MainActivity.this, Task.class);
// start the activity connect to the specified class
startActivity(intent);
}
});
}
}
' 'Кроме того, вот мой файл xml.
'' '
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="@drawable/appbackground">
<LinearLayout
android:id="@+id/time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:fontFamily="@assets/HelveticaNeue"
android:textColor="#000000"
android:textSize="150dp"
android:layout_centerInParent="true"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:paddingBottom="20dp"
>
<ImageButton
android:id="@+id/list"
android:layout_height="70dp"
android:layout_width="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/list"
android:layout_weight="1"
android:paddingLeft="30dp"
android:paddingRight="30dp"
/>
<ImageButton
android:layout_height="70dp"
android:layout_width="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/homerun"
android:layout_weight="1"
android:paddingLeft="30dp"
android:paddingRight="30dp"
/>
<ImageButton
android:layout_height="70dp"
android:layout_width="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/plus"
android:layout_weight="1"
android:paddingLeft="30dp"
android:paddingRight="30dp"
/>
</LinearLayout>
</RelativeLayout>
' ''