I have an application with various tabs (on a tabhost). Each tab is an activity that extends activity and has some textfields
and things on it.
Now, I need that my tabs have inside a listview, but in the example from Android developer guide says that you have to extend ListActivity and not Activity.
Basically, I need to merge these two tutorials:
List View
Layouts
How can I use a listview
without extending listactivity
on my class?
My XML file:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</LinearLayout>
</TabHost>
This example demonstrates how do I dynamically add elements in ListView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
It's almost the same. Basing myself on ListView's tutorial.
Instead of doing:
setListAdapter();
do the following:
<ListView>
in your layoutActivity
private ListView mListView;
on the onCreate()
method do this:
mListView = (ListView) findViewById(R.id.your_list_view_id);
mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
I don't remember if ListActivity
provides something more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With