我的应用程序使用一个按钮,单击该按钮会转到显示 ListView 的新 Activity 。所有这一切似乎工作正常。但是 ListView 显示在与按钮相同的 Activity 之上。不单独显示。所以我在后台看到了主要 Activity 和重叠的 ListView !这个问题能解决吗?我的代码如下: 按钮点击事件:
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(Assignments.this, ViewEntry.class);
startActivity(i);
}
});
和 ListView 代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.database_view);
//ListView lv = (ListView)findViewById(R.id.listView1);
dbControl = new DatabaseControl(ViewEntry.this);
dbControl.open();
ArrayList<String> data = dbControl.getData();
if (data.equals(null)) {
Toast.makeText(ViewEntry.this, "Database Empty!", Toast.LENGTH_LONG)
.show();
} else {
final Dialog notice = new Dialog(this);
final TextView msgbox = new TextView(this);
//ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data);
setListAdapter(new ArrayAdapter<String>(ViewEntry.this,
android.R.layout.simple_list_item_1, data));
final ListView listView = getListView();
//lv.setAdapter(arrayAdapter);
//lv.setTextFilterEnabled(true);
}
}
我的xml代码如下。但我认为这没有什么不同,因为我没有使用过 setContentView
。使用 setContentView(R.layout.database_view);
返回调试错误。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:fadingEdge="vertical"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
</ListView>
<TextView
android:id="@+id/textViewDatabase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/>
提前致谢!
最佳答案
将第二个 Activity 布局的背景颜色更改为不透明。当您启动第二个 Activity 时,第一个 Activity 会暂停并进入后台,但仍然存在,就像显示对话框时一样。
编辑:
Activity 默认不透明,检查你是否在 styles.xml 中正确定义了 appTheme 并确保你没有在任何地方使用 android:theme="@android:style/Theme.Translucent"或 "#00XXXXXX"颜色在您的样式或 list 文件中。
如果样式一切正常,那么我不知道为什么你的 ListActivity 仍然是透明的,但你可以通过将以下布局设置为 contentView 来更改它:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ad_catalog_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#888888" <!-- example non-transparent color -->
android:orientation="vertical" >
<ListView
android:id="@android:id/list" <!-- has to be @android:id/list for ListActivity -->
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
或者通过设置 ListView 背景颜色:
getListView().setBackgroundColor(Color.rgb(xxx, xxx, xxx));
关于android - ListView显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15745486/