1

私のアプリは、クリックするとリストビューを表示する新しいアクティビティに移動するボタンを使用しています。これはすべて正常に機能しているようです。ただし、リスト ビューはボタンを使用して同じアクティビティの上に表示されます。個別には表示されません。だから、バックグラウンドでメインのアクティビティと重複したリストビューが表示されます! この問題は解決できますか? 私のコードは次のとおりです: ボタンのクリック イベント:

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);
        }
    });

リストビューのコード:

    @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=""/>

前もって感謝します!

4

3 に答える 3

2

2 番目のアクティビティ レイアウトの背景色を非透明に変更します。2 番目のアクティビティを開始すると、最初のアクティビティは一時停止されてバックグラウンドに入りますが、ダイアログが表示されているときのようにまだそこにあります。

編集:

アクティビティはデフォルトでは透明ではありません。styles.xml で appTheme が適切に定義されているかどうかを確認し、スタイルのどこにも android:theme="@android:style/Theme.Translucent" または "#00XXXXXX" の色を使用していないことを確認してください。またはマニフェスト ファイル。

スタイルに問題がない場合、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));
于 2013-04-01T14:42:18.797 に答える
0

Instead of using transparent background color try using non transparent colors

try below code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:background="#b3b3b3"
android:fadingEdge="vertical"
android:orientation="vertical" >
于 2013-04-02T11:13:27.910 に答える
-1

インテントを使用して他のアクティビティに移動し、新しいアクティビティでリスト ビュー自体を作成します。ボタンを使用してインテントをトリガーします。

于 2013-04-01T15:13:55.410 に答える