Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未显示第二个活动的内容_Android - Fatal编程技术网

Android 未显示第二个活动的内容

Android 未显示第二个活动的内容,android,Android,所以,第二个活动的内容在应用程序运行时不会出现,尽管内容是在xml设计中显示的。在Android Studio上用Java编程。在类似的文章中,答案并没有帮助。我也试着在第二个活动中加入一个元素,同样的结果。提前谢谢 这是来自MainActivity.java的代码: package todo.beginner.com.carchooser2; import android.content.Intent; import android.os.Bundle; import android.sup

所以,第二个活动的内容在应用程序运行时不会出现,尽管内容是在xml设计中显示的。在Android Studio上用Java编程。在类似的文章中,答案并没有帮助。我也试着在第二个活动中加入一个元素,同样的结果。提前谢谢

这是来自
MainActivity.java
的代码:

package todo.beginner.com.carchooser2;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

import static todo.beginner.com.carchooser2.R.id.checkBoxPrice;
import static todo.beginner.com.carchooser2.R.id.checkBoxGas;
import static todo.beginner.com.carchooser2.R.id.checkBoxYear;
import static todo.beginner.com.carchooser2.R.id.checkBoxMileage;
import static todo.beginner.com.carchooser2.R.id.checkBoxCapacity;

public class MainActivity extends AppCompatActivity {
    private CheckBox check1, check2, check3, check4, check5;
    private static Button button_next;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerToCeckBox();
        OnClickButtonListener();
    }

    public void OnClickButtonListener() {
        button_next = (Button)findViewById(R.id.button);
        button_next.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent("todo.beginner.com.SecondActivity");
                        startActivity(intent);

                    }
                }
        );


    }

    public void addListenerToCeckBox() {
        check1 = (CheckBox)findViewById(checkBoxCena);
        check1.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (((CheckBox)v).isChecked()){
                            Toast.makeText(MainActivity.this,
                                    "Price is chosen", Toast.LENGTH_LONG).show();
                        }
                    }
                }
        );
        check2 = (CheckBox)findViewById(checkBoxGads);
        check2.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (((CheckBox)v).isChecked()){
                            Toast.makeText(MainActivity.this,
                                    "Year is chosen", Toast.LENGTH_LONG).show();
                        }
                    }
                }
        );
        check3 = (CheckBox)findViewById(checkBoxTilpums);
        check3.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (((CheckBox)v).isChecked()){
                            Toast.makeText(MainActivity.this,
                                    "Engine capacity is chosen", Toast.LENGTH_LONG).show();
                        }
                    }
                }
        );
        check4 = (CheckBox)findViewById(checkBoxDegviela);
        check4.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (((CheckBox)v).isChecked()){
                            Toast.makeText(MainActivity.this,
                                    "Gas consumption is chosen", Toast.LENGTH_LONG).show();
                        }
                    }
                }
        );
        check5 = (CheckBox)findViewById(checkBoxNobraukums);
        check5.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (((CheckBox)v).isChecked()){
                            Toast.makeText(MainActivity.this,
                                    "Mileage is chosen", Toast.LENGTH_LONG).show();
                        }
                    }
                }
        );

    }



}
package todo.beginner.com.carchooser2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
    }
}
这来自
活动\u 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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="todo.raitis.com.carchooser.MainActivity">

    <CheckBox
        android:text="Price"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/checkBoxPrice"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="67dp" />

    <CheckBox
        android:text="Year"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/checkBoxPrice"
        android:layout_alignRight="@+id/checkBoxPrice"
        android:layout_alignEnd="@+id/checkBoxPrice"
        android:layout_marginTop="33dp"
        android:id="@+id/checkBoxYear" />

    <CheckBox
        android:text="Engine Capacity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="37dp"
        android:id="@+id/checkBoxCapacity"
        android:layout_below="@+id/checkBoxYear"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <CheckBox
        android:text="Gas"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/checkBoxCapacity"
        android:layout_alignRight="@+id/checkBoxCapacity"
        android:layout_alignEnd="@+id/checkBoxCapacity"
        android:layout_marginTop="30dp"
        android:id="@+id/checkBoxGas" />

    <CheckBox
        android:text="Mileage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/checkBoxGas"
        android:layout_alignRight="@+id/checkBoxGas"
        android:layout_alignEnd="@+id/checkBoxGas"
        android:layout_marginTop="33dp"
        android:id="@+id/checkBoxMileage" />

    <Button
        android:text="Next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp"
        android:id="@+id/button" />

    <TextView
        android:text="Choose criteria!"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>
这来自activity_second.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp">

    <TableRow
        android:background="#607D8B"
        android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Car Name" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Price" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Year" />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Gas" />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Mileage" />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Capacity" />
    </TableRow>

    <TableRow
        android:background="#ECEFF1"
        android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Audi" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="5000" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="2001" />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="7" />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="280000" />
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="2.5" />
    </TableRow>
</TableLayout>


不要认为您正确启动了活动。尝试更改
Intent Intent=new Intent(“todo.初学者.com.SecondActivity”)
意图意图=新意图(MainActivity.this,SecondActivity.class)在主活动中。

不要认为您正确启动了活动。尝试更改
Intent Intent=new Intent(“todo.初学者.com.SecondActivity”)
意图意图=新意图(MainActivity.this,SecondActivity.class)在主活动中。

您使用的意图不正确。应该是:

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

您使用的意图不正确。应该是:

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

你能替换Intent=newintent(“todo.初学者.com.SecondActivity”);with Intent Intent=new Intent(MainActivity.this,SecondActivity.class);你能替换Intent=newintent(“todo.初学者.com.SecondActivity”);with Intent Intent=new Intent(MainActivity.this,SecondActivity.class);