activity不能正常显示的问题
有个问题,我从一个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>