activity不能正常显示的问题

bjskyhorse 2010-11-12 11:07:18
有个问题,我从一个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>

...全文
1629 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
mvpsendoh 2011-07-06
  • 打赏
  • 举报
回复
楼主太小气了,没有一点分享精神,只想别人帮你解决问题,却不帮别人解决问题
bjskyhorse 2011-07-06
  • 打赏
  • 举报
回复
如果遇到此类问题,请认真检查manifest文件和layout文件。比如启动方式,布局。
csuchenpeng1119 2011-05-30
  • 打赏
  • 举报
回复
我也晕,没下文,同样遇到跟楼主一样的问题!!楼主分享下 答案!
smilepander 2011-05-23
  • 打赏
  • 举报
回复
晕 没下文了 解决了也不说说怎么解决的。。。。。。
xiangchen2010 2011-04-22
  • 打赏
  • 举报
回复
请问楼主刚开始的那个问题是如何解决的?我现在也遇到了类似的问题。
bjskyhorse 2010-12-17
  • 打赏
  • 举报
回复
这个问题已经解决了,但是有另外一个问题,我是想在界面上上下顺序安排两个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>
bjskyhorse 2010-11-19
  • 打赏
  • 举报
回复
我试了,改layout文件或者什么,都会出现提示说activity pause time out。。。。
piaolankeke 2010-11-16
  • 打赏
  • 举报
回复
你的logcat提示错误信息是什么啊?
bjskyhorse 2010-11-16
  • 打赏
  • 举报
回复
DEBUG似乎是这里出问题了,产生了一个exception.
Intent intent = new Intent();
intent.setClass(MainScreen.this, Login_Activiy.class);
startActivity(intent);
bjskyhorse 2010-11-16
  • 打赏
  • 举报
回复
继续叮问
bjskyhorse 2010-11-16
  • 打赏
  • 举报
回复
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

bjskyhorse 2010-11-15
  • 打赏
  • 举报
回复
请帮忙看看
bjskyhorse 2010-11-15
  • 打赏
  • 举报
回复
我改成也是一样啊,而且即使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"
/>
hyfeng_ccle 2010-11-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bjskyhorse 的回复:]
EditText属性设置如下,没看出有什么问题,在模拟器上是一片黑的什么也没有

<EditText android:id="@+id/account_input"
android:textSize="24sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
andro……
[/Quote]

android:layout_below="@id/message_view"
两个EditView都是一样的?不会重叠咩?
bjskyhorse 2010-11-12
  • 打赏
  • 举报
回复
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"
/>
foley_liao 2010-11-12
  • 打赏
  • 举报
回复
是不是你的Button和EditText的属性设置问题,你先别设置太多的属性试试
bjskyhorse 2010-11-12
  • 打赏
  • 举报
回复
我怀疑还是起另外一个activity的问题

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧