Aditya
Aditya

Reputation: 1261

ListView display bug

My app uses a button which when clicked goes to a new activity which displays a list view. All of this seems to be working fine. But the list view is displayed on top of the same activity with the button. It is not displayed separately. So i see the main activity in the background and the overlapped listview! Can this problem be solved? My code is as follows: Button CLick event:

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

And the listview code:

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

My xml code is as follows. But i don't think it makes a difference since i haven't used the setContentView. Using setContentView(R.layout.database_view); returns a debug error.

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

Thanks in advance!

Upvotes: 1

Views: 296

Answers (3)

Dasari
Dasari

Reputation: 438

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" >

Upvotes: 0

Leszek
Leszek

Reputation: 6598

Change background color of second activity layout to non-transparent. When you start second Activity the first is paused and goes into background but is still there like when dialog is shown.

Edit:

Activity is not transparent by default, check if you have properly defined appTheme in styles.xml and make sure you don't use android:theme="@android:style/Theme.Translucent" or "#00XXXXXX" color anywhere in your styles or manifest file.

If there is everything OK with styles then I don't know why your ListActivity is still transparent but you can change this by setting following layout as 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>

or by setting ListView background color:

getListView().setBackgroundColor(Color.rgb(xxx, xxx, xxx));

Upvotes: 2

code
code

Reputation: 2163

Use an Intent to go to the other activity and create a list view itself in the new activity. Use the Button to trigger the intent.

Upvotes: -1

Related Questions