简体   繁体   中英

android - Add a ListActivity in Activity

I would like to add a ListActivity in Activity .

For Example, there's a title and a button on top of the page of the Activity , and the ListActivity is the main content of the Activity . The button would be able to load different ListActivity below.

When swiping left and right, there will be new Activity s and new content in the main section.

Swipe left and right to change the full screen, toggle the button to change the content in the main section (the box with shades and the text "ListActivity").

Edit: Like this image:

在此处输入图片说明

How can I do that?

I've tried to use Intent , but it starts a new Intent and the content of the ListActivity occupies the full screen.

Thanks.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ListView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/list"
    />
</LinearLayout>



public class StockList extends ListActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ListView listView = (ListView) findViewById(R.id.list);
        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2" };  

        // First paramenter - Context
        // Second parameter - Layout for the row
        // Third parameter - ID of the TextView to which the data is written
        // Forth - the Array of data
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, 
                android.R.id.text1, values);

        // Assign adapter to ListView
        listView.setAdapter(adapter);
    }

}

u can do it like this

import android.os.Bundle;
import android.app.ListActivity;
import android.widget.ArrayAdapter;


public class MyListActivity extends ListActivity {

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" };

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, values);
    setListAdapter(adapter);
 }
}

for more detail check Android ListView and ListActivity - Tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM