繁体   English   中英

主活动中的项目不会显示

[英]Items on the Main Activity won't show up

我只是坚持这个问题,我要做的是主要活动,首先检查不同活动上保存的首选项,然后返回以继续setContentView()等。

注册活动可以正常工作,但是当该活动要返回到主活动时。 主活动将不会显示ListView,Button等,仅显示操作栏。

我不确定问题出在哪里,有人可以帮我这个忙。

MainActivity.Java

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

    /**
     * default values.
     */
    if (Settings.isRegistered(this)) {
        Intent i = new Intent(this, Register.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        this.startActivity(i);
        return;
    }

    setContentView(R.layout.Msg);

    messageList = (ListView) findViewById(R.id.message_list);
    .
    .
    .
}

Msg.xml

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

    <EditText
        android:id="@+id/message_text"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_weight="0.7"
        android:hint="@string/message_edit_text"
        android:inputType="text"
        android:textAppearance="?android:attr/textAppearanceMedium"  />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/chatroom"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="0.7"
            android:hint="@string/chatroom_text"
            android:inputType="text"
            android:textAppearance="?android:attr/textAppearanceMedium"/>

        <Button
            android:id="@+id/send_button"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="0.3"
            android:text="@string/sendlabel"
            android:textAppearance="?android:attr/textAppearanceMedium"/>

    </LinearLayout>

    <ListView
        android:id="@+id/messagelist"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll" >
    </ListView>

</LinearLayout>

onCreate()的末尾设置代码的这一部分:

    /**
     * default values.
     */
    if (Settings.isRegistered(this)) {
        Intent i = new Intent(this, Register.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        this.startActivity(i);
    }

当然没有return

startActivity之后删除return语句。 我建议将setContentView移动到super.onCreate下面的super.onCreate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM