Activity layout not showing

风流意气都作罢 提交于 2020-07-16 03:16:51

问题


Im trying to call a second activity from my Main Activity, using this code

Intent goToOrder = new Intent(ListOfOrdersActivity.this, OrderSummaryActivity.class);
startActivity(goToOrder);

Being my OrderSummaryActivity:

public class OrderSummaryActivity extends ActionBarActivity {

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.order_summary);
    }
}

But the layout wont show on this activity, just a blank page. This is the xml of the layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/name"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"
        />
    <TextView
        android:id="@+id/order_resume_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/quantity"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_quantity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/whipped_cream"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_whipped_cream"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/chocolate"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_chocolate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/order_summary_total"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_margin="10dp"/>
    <TextView
        android:id="@+id/order_resume_total"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>

Any hint?


回答1:


Try changing your OrderSummaryActivity.class to :

    public class OrderSummaryActivity extends ActionBarActivity
    {

        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.order_summary);
        }
    }



回答2:


try overriding

public void onCreate(Bundle savedInstanceState)

instead of

public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)


来源:https://stackoverflow.com/questions/37367101/activity-layout-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!