On Aug 16, 5:39 pm, Mark Murphy <[email protected]> wrote:
> Aayush wrote:
> > Hi,
>
> > I want to show many listviews in one activity. Something like
>
> > Textview
> > Listview
> > TextView
> > Listview
> > ..........
>
> > Every listview has different type of adapter. For this, I made the
> > activity class like:-
>
> > public class ListTestActivity extends ListActivity {
>
> > public void onCreate(Bundle savedInstanceState){
> >            super.onCreate(savedInstanceState);
> >            setContentView(R.layout.screen); // screen.xml file
> >                 setListAdapter(new CustomAdapter(this);
> >                 ...............................
> > }
>
> > class CustomAdapter extends ArrayAdapter {
> >            Activity context;
>
> > public View getView(int position, View convertView,  ViewGroup parent)
> > {
> > ...............................
> > }
>
> > In screen.xml file if I define Listview like:-
>
> > <ListView
> >    android:id="@android:id/list"
>
> > I can get one listview with the custom adapter in this kind of
> > arrangement.
> > But when I replace it by  android:id="@+id/list2" and use it as
> > R.id.list2, it throws nullpointer exception.
>
> > Any pointers for this problem??
>
> ListView thisIsYourSecondList=(ListView)findViewById(R.id.list2);
>
> thisIsYourSecondList.setAdapter(ohSomeAdapterGoesHere);
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Looking for Android opportunities?http://wiki.andmob.org/hado

My 5 cents :)

I assume it'll be better to use Activity instead of ListActivity to
provide common processing logic (provided by Mark Murphy) for list
views:

ListView firstList=(ListView)findViewById(R.id.list1);
firstList.setAdapter(firstAdapter);

ListView secondList=(ListView)findViewById(R.id.list2);
secondList.setAdapter(secondAdapter);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to