有个问题,我从一个activity名为mainscreen去启动另外一个activity login,那个activity显示的有些问题,只显示出来在
AndroidManifest.xml里的login_text,原本应该出现在这个activity的EditText和Button等都没有显示出来。
通过调试,发现如下:
A Starting activity:Intent---这里是发了intent去启动activity
但是后面接着是
A activity pause timeour for HistoryRecord(com.test/com.test.MainScreen}}
A launch timeout has expired,giving up wake lock
A activity idle timeout for HistoryRecord(com.test/com.test.Login_Activity}
在AndroidManifest.xml里面我是这样写的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".mainscreen"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>    
       <activity android:name=".Login_Activiy"
        android:label="@string/login_text">
       <intent-filter>      
                <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
       </activity>    </application>
</manifest>  在第一个activity,是list形式,点击其中一项,调用另外一个activity,对应的代码如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "OnCreate");
setContentView(R.layout.main);
showMenuView();
}
private void showMenuView() { Log.d(TAG, "Show Menu View");
setContentView(R.layout.main); mListView = (ListView) findViewById(R.id.myListView);
mTextView = (TextView) findViewById(R.id.myTextView);
mTextView.setText(getResources().getString(R.string.menu));
myOpt = new String[] { getResources().getString(R.string.login),
getResources().getString(R.string.query),
getResources().getString(R.string.transfer),
getResources().getString(R.string.logout) };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(demo_UI.this,
android.R.layout.simple_list_item_1, myOpt); mListView.setAdapter(adapter);
mListView.setItemsCanFocus(true);
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mListView.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if (arg0.getAdapter().getItem(arg2).toString() == myOpt[0]
.toString()) {
getResources().getString(R.string.login);
Log.d(TAG, "start login activity");
Intent intent = new Intent();
intent.setClass(MainScreen.this, Login_Activiy.class);
startActivity(intent);

}
});而login activity的代码如下:public void OnCreate(Bundle icicle) {
setTitle(getString(R.string.login_text));
setContentView(R.layout.login_activity);
TextView textView = (TextView) findViewById(R.id.message_view);
textView.setText(text);
m_account = (EditText) findViewById(R.id.account_input);
m_account.addTextChangedListener(mAccountWatcher); m_pwd = (EditText) findViewById(R.id.password_input);
m_pwd.addTextChangedListener(mPwdWatcher); mOk = (Button) findViewById(R.id.ok);
mOk.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Log.d(TAG, "On Click OK ,");
if ((m_account.getText().length() < minLen)
|| (m_pwd.getText().length() < minLen)) {
StringBuilder sb = new StringBuilder();
sb.append(getString(R.string.cannot_be_less_than_min));
sb.append(" ");
sb.append(minLen);
text = sb.toString();
Toast toast = Toast.makeText(getApplication(), text,
Toast.LENGTH_LONG);
toast.show();
} else {
// start login session here
} } }); mCancel = (Button) findViewById(R.id.cancel);
mCancel.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Log.d(TAG, "On Click cancel");
finish(); } }); super.onCreate(icicle); }对应的login activity的XML文件如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/get_input_activity"
        android:paddingLeft="20dip"
        android:paddingRight="20dip"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >        <TextView android:id="@+id/message_view"
    android:textSize="24sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <EditText android:id="@+id/input"
            android:textSize="24sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/message_view"
            />
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/input">
            <Button android:id="@+id/ok"
                android:textSize="24sp"
                android:textColor="#FFFFFFFF"
                android:layout_marginTop="8dip"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:text="@string/ok" />
            <Button android:id="@+id/cancel"
                android:textSize="24sp"
                android:textColor="#FFFFFFFF"
                android:layout_marginTop="8dip"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/ok"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:text="@string/cancel" />
            <Button android:id="@+id/help"
                android:textSize="24sp"
                android:textColor="#FFFFFFFF"
                android:layout_marginTop="8dip"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/cancel"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:text="@string/help" />
        </LinearLayout>    </RelativeLayout>
</ScrollView>

解决方案 »

  1.   

    我怀疑还是起另外一个activity的问题
      

  2.   

    是不是你的Button和EditText的属性设置问题,你先别设置太多的属性试试
      

  3.   

    EditText属性设置如下,没看出有什么问题,在模拟器上是一片黑的什么也没有  <EditText android:id="@+id/account_input"
                android:textSize="24sp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/message_view"
                />
           <EditText android:id="@+id/password_input"
               android:textSize="24sp"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_below="@id/message_view"
            />
      

  4.   


    android:layout_below="@id/message_view"
    两个EditView都是一样的?不会重叠咩?
      

  5.   

    我改成也是一样啊,而且即使2个EDITEtext出现重叠,也不应该是界面上黑乎乎一片啊。似乎根本就没有调用到OnCreate里面加载layout文件
          <EditText android:id="@+id/account_input"
                android:textSize="24sp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/message_view"
                />
                 <EditText android:id="@+id/password_input"
               android:textSize="24sp"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_below="@id/account_input"
            />  
      

  6.   

    DEBUG似乎是这里出问题了,产生了一个exception.
    Intent intent = new Intent();
    intent.setClass(MainScreen.this, Login_Activiy.class);
    startActivity(intent);
      

  7.   

    你的logcat提示错误信息是什么啊?
      

  8.   

    logcat里面提示:
    Starting activity:Intent{comp={com.test/com.test.Login_Activity}}
    Activity pause time out for HistoryRecord{com.test/com.test.Login_Activity}
    Launch time out has expired,giving up wake lock
      

  9.   

    我试了,改layout文件或者什么,都会出现提示说activity pause time out。
      

  10.   

    这个问题已经解决了,但是有另外一个问题,我是想在界面上上下顺序安排两个EditText,最下面是两个按钮。
    但是两个EditText只显示出一个。我的XML文件时这样写的,我想到是第二个EditText password_input在第一个EditText  account_input下面,这样对吗<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_activity"
            android:paddingLeft="20dip"
            android:paddingRight="20dip"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >        <TextView android:id="@+id/message_view"
        android:textSize="24sp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"/>
            <EditText android:id="@+id/account_input"
                android:textSize="24sp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/message_view"
                />
                 <EditText android:id="@+id/password_input"
               android:textSize="24sp"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_below="@id/account_input"
            />      
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/password_input">
                <Button android:id="@+id/ok"
                    android:textSize="24sp"
                    android:textColor="#FFFFFFFF"
                    android:layout_marginTop="8dip"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:layout_weight="1"
                    android:text="@string/ok" />
                <Button android:id="@+id/cancel"
                    android:textSize="24sp"
                    android:textColor="#FFFFFFFF"
                    android:layout_marginTop="8dip"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/ok"
                    android:layout_gravity="right"
                    android:layout_weight="1"
                    android:text="@string/cancel" />         
            </LinearLayout>    </RelativeLayout>
    </ScrollView>
      

  11.   

    如果遇到此类问题,请认真检查manifest文件和layout文件。比如启动方式,布局。