Reputation: 1236
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.
Upvotes: 1
Views: 1317
Reputation: 4114
<?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);
}
}
Upvotes: 1
Reputation: 5784
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
Upvotes: 0