I have a SQLite Database with 3 records for example:
1 - Name1 - Do wash
2 - Name2 - Do this
3 - Name3 - Do that
Now I want to start one activity after another (for each record) when user presses a button. The Activity is always the same with other content.
So what is the best way to do this?
My thoughts are following:
- Make a for loop and use StartActivityForResult(...)
- Pass data throug all activities using intent
- Create a temporary table and read data in each activity
- Change only the content of the layout, but don't know how i could do this
So any suggestions on this?
I think for showing same type of view on multiple content you should use fragment with viewpager.
I am just suggesting code to you for viewpager and fragment -
layout for content (pages.xml)-
<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"
tools:context=".MainActivity"
android:id="#+id/rel" >
<TextView
android:id="#+id/pageContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Main activity content(activity_main.xml) -
<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"
tools:context=".MainActivity" >
<RelativeLayout
android:id="#+id/relativeTextview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header"
android:padding="5dp" >
<android.support.v4.view.ViewPager
android:id="#+id/reviewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
</RelativeLayout>
Pager adapter for setting on viewpager(ViewPagerAdapter.java)-
public class ViewPagerAdapter extends PagerAdapter {
int size;
Activity act;
View layout;
TextView pagecontent;
Button click;
public ViewPagerAdapter(MainActivity mainActivity, int noofsize) {
// TODO Auto-generated constructor stub
size = noofsize;
act = mainActivity;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return size;
}
#Override
public Object instantiateItem(View container, int position) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) act
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.pages, null);
pagecontent = (TextView) layout.findViewById(R.id.pageContent);
int pagenumberTxt=position + 1;
pagecontent.setText("Now your in Page No " +pagenumberTxt );
((ViewPager) container).addView(layout, 0);
return layout;
}
#Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
#Override
public Parcelable saveState() {
return null;
}
// }
}
Now in main activity((MainActivity.java) -
public class MainActivity extends Activity {
int noofsize = 6;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPagerAdapter adapter = new ViewPagerAdapter(MainActivity.this,
noofsize);
ViewPager myPager = (ViewPager) findViewById(R.id.reviewpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
and do not forget to mention activity in manufest.xml.
In pages.xml you can add the button on on click of this button you can change the view for next and previous(mPager.setCurrentItem(position)) using listener.
Using activities for this will take a toll on RAM. Use fragments instead.
Answering your original question, as you have cited, make use of the onActivityResult() and as for your concern in this:
-Change only the content of the layout, but don't know how i could do this
Make use of the passed data from intent and handle accordingly.
Related
I want to show a ViewPager with all the days of the week with a preview of the following and previous item of the current one.
I've tried a lot of solutions suggested from stackoverflow but none of them is working. I don't wont to use fragments in the ViewPager so I've used a PagerAdapter.
See this image:
My starting point is:
activity_main.xml
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Choose a day of the week:" />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/weekOfTheDayPager"/>
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpAdapter();
}
private void setUpAdapter() {
ViewPager _mViewPager = (ViewPager) findViewById(R.id.weekOfTheDayPager);
final String[] daysOfTheWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
final Context myContext = getBaseContext();
_mViewPager.setAdapter(new PagerAdapter() {
#Override
public int getCount() {
return daysOfTheWeek.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
#Override
public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = LayoutInflater.from(myContext);
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.dayoftheweeklayout, collection, false);
((TextView) layout.findViewById(R.id.dayOfTheWeekTextView)).setText(daysOfTheWeek[position]);
collection.addView(layout);
return layout;
}
#Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}
});
}}
and finally the layout for the ViewPager item:
dayoftheweeklayout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/dayOfTheWeekTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sunday"
android:layout_gravity="center_horizontal"/>
</FrameLayout>
Any suggestion will be appreciated.
So it looks like you want a carousel view.
Here's the recipe:
First, in order to show pages to the side in ViewPager, you need to provide some padding on the sides and then set clipToPadding to false:
<android.support.v4.view.ViewPager
android:id="#+id/weekOfTheDayPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingEnd="#dimen/view_pager_padding"
android:paddingLeft="#dimen/view_pager_padding"
android:paddingRight="#dimen/view_pager_padding"
android:paddingStart="#dimen/view_pager_padding"/>
Next, you need to override getPageWidth in your PagerAdapter to tell the ViewPager that you want to display three pages at a time:
#Override
public float getPageWidth(int position) {
return 1F / 3F;
}
Then you need to tell the ViewPager to use a custom PageTransformer:
viewPager.setPageTransformer(false, new MyPageTransformer());
...
public static class MyPageTransformer implements ViewPager.PageTransformer {
private ArgbEvaluator mColorFade = new ArgbEvaluator();
#Override
public void transformPage(View page, float position) {
// position is 0 when page is centered (current)
// -1 when page is all the way to the left
// +1 when page is all the way to right
// Here's an example of how you might morph the color
int color = mColorFade(Math.abs(position), Color.RED, Color.GRAY);
TextView tv = (TextView) page.findViewById(R.id.dayOfTheWeekTextView);
tv.setTextColor(color);
}
}
There's probably something I forgot, but search SO for "android viewpager carousel" and you will find an answer in there somewhere.
I have a viewPager which uses FragmentStatePagerAdapter as adapter and in fragment class which is used in getItem() function of adapter I add some other fragments at runtime using fragment manager. Fragments are shown correctly for page zero (starting page) but for any other page I should swipe over it an then swipe back to it to see contents.(as I checked each swipe causes inner fragments and fragment managers behave correctly even the first time but nothing is shown at first)
Any solution is appreciated
Thanks in advance
adapter code in main class
class FragmntProducer extends FragmentStatePagerAdapter{
public FragmntProducer(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
#Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return new PagerFragment(pager.getCurrentItem());
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return Integer.MAX_VALUE;
}
}
fragment class used for viewpager
public class PagerFragment extends Fragment {
WeekView rowOne , rowTwo , rowThree , rowFour , rowFive , rowSix;
int cis;
public PagerFragment(int ci) {
// TODO Auto-generated constructor stub
cis = ci;
// Toast.makeText(getContext(), ci+"under construct", Toast.LENGTH_SHORT).show();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.pager_fragment_layout, container, false);
Toast.makeText(getContext(),"page: "+cis,Toast.LENGTH_SHORT).show();
// rowOne = new WeekView();
// getFragmentManager().beginTransaction().add(R.id.week_one, rowOne).commit();
rowTwo = new WeekView();
getFragmentManager().beginTransaction().add(R.id.week_two, rowTwo).commit();
// rowThree = new WeekView();
// getFragmentManager().beginTransaction().add(R.id.week_three, rowThree).commit();
rowFour = new WeekView();
getFragmentManager().beginTransaction().add(R.id.week_four, rowFour).commit();
rowFive = new WeekView();
getFragmentManager().beginTransaction().add(R.id.week_five, rowFive).commit();
rowSix = new WeekView();
getFragmentManager().beginTransaction().add(R.id.week_six, rowSix).commit();
super.onCreateView(inflater, container, savedInstanceState);
return layout;
}
}
xml layout for fragment of viewPager
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<fragment
android:id="#+id/week_one"
android:layout_width="match_parent"
android:layout_height="40dp"
android:name="com.cal.calendar.WeekView"/>
<FrameLayout
android:id="#+id/week_two"
android:layout_width="match_parent"
android:layout_height="40dp"/>
<fragment
android:id="#+id/week_three"
android:layout_width="match_parent"
android:layout_height="40dp"
android:name="com.cal.calendar.WeekView"/>
<FrameLayout
android:id="#+id/week_four"
android:layout_width="match_parent"
android:layout_height="40dp"/>
<FrameLayout
android:id="#+id/week_five"
android:layout_width="match_parent"
android:layout_height="40dp"
android:name="com.cal.calendar.WeekView"/>
<FrameLayout
android:id="#+id/week_six"
android:layout_width="match_parent"
android:layout_height="40dp"/>
Everything I have seen is overkill. I am simply looking for a way to have some part of my app scroll through several text snippets when swiping left/right. Imagine an image gallery that you scroll through, but just a line of text for each instead of an image. Thanks!
You can have a look at my other posts for more detailed answer. The explanation is very simple in my other posts.
How to properly use fragments with ViewPager?
Multiple ViewPagers in on Activity
How to swipe xml layouts using ViewPager
These are few examples you can find helpful. Hope this helps.. :)
If still having some issues with those answers, take a look at this simple example:
Just follow simple steps here:
Step 1: Create layout for your view pager:(activity_main.xml)
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#333333">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Step 2: Create another layout to hold your textview items: (items.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/text_view1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#94999F"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:text="Hello"
android:textColor="#FFFFFF"
android:textSize="17sp"
android:textStyle="bold"
android:visibility="visible" />
</LinearLayout>
Step 3: In you Main Activity create a class for your adapter or you can create a separate class for your adapter. This is just an adapter inside the same class. Here's the full code:
public class MainActivity extends Activity {
ViewPager mViewPager;
String[] items = { "one", "two", "three", "four", "five" };
ArrayList<String> mArrayList = new ArrayList<String>();
Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
/*for (String s : items) {
mArrayList.add(s);
}*/
for(int i = 0;i<100;i++){
mArrayList.add("Item " + i);
}
mViewPager = (ViewPager) findViewById(R.id.pager);
MyAdapter mAdapter = new MyAdapter(context, mArrayList);
mViewPager.setAdapter(mAdapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/*Here's the adapter*/
private class MyAdapter extends PagerAdapter {
ArrayList<String> someList = new ArrayList<String>();
Context context;
public MyAdapter(Context context, ArrayList<String> newsomeList) {
super();
this.context = context;
this.someList = newsomeList;
}
#SuppressLint("NewApi")
#Override
public void finishUpdate(ViewGroup container) {
// TODO Auto-generated method stub
super.finishUpdate(container);
}
#Override
public int getCount() {
return someList.size();
}
#Override
public boolean isViewFromObject(View collection, Object object) {
return collection == ((View) object);
}
#Override
public Object instantiateItem(View collection, int position) {
// Inflating layout
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Setting view you want to display as a row element
View view = inflater.inflate(R.layout.items, null);
TextView itemText = (TextView) view.findViewById(R.id.text_view1);
// Getting reference for text view and inflate the view for Answers
try {
itemText.setText(someList.get(position));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
((ViewPager) collection).addView(view, 0);
return view;
}
#Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}
}
}
And that's you need .. :)
Hope this will help you.. Its a very simple example for what you need.. Good Luck .. :)
take a look at this: Using ViewPager for Screen Slides
You can use HorizontalScrollView. An example is here. Instead of Buttons, you can use TextView to serve you puroise.
Or else you can use ViewPager also. Already others have given you tutorial just follow that. But I think, to serve your purpose HorizontalScrollView is needed.
I'm working on an app which uses a ViewPager with two swiping views (first_page.xml and second_page.xml) and has one activity (activity_main.xml).
When in the main activity class I try to access TextView (which is located in the first_page.xml) using findViewById it can't be found.
This is my activity_main.xml
<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"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
This is my first_page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/someText"
android:text="example"
android:textSize="42sp" >
</TextView>
</LinearLayout>
This is my customPagerAdapter
public class CustomPagerAdapter extends PagerAdapter {
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0: {
resId = R.layout.first_page;
break;
}
case 1: {
resId = R.layout.second_page;
break;
}
}
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
}
#Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
#Override
public Parcelable saveState() {
return null;
}
#Override
public int getCount() {
return 2;
}
}
And this is my MainActivity, where I want get the first_page layout, find its TextView called someText, and set a new custom font.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create and set adapter
CustomPagerAdapter adapter = new CustomPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.pager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
/*
* Here i want to set a new custom font but it seems the someText can't
* be found because the Activity searches for it in the
* layout.activity_main and not in the layout.first_page
*/
TextView textView = (TextView) findViewById(R.id.someText);
Typeface font = Typeface.createFromAsset(getAssets(), "roboto_thin.ttf");
textView.setTypeface(font);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I'm struggling for two days with this problem.
Any suggestions?
The textview is encapsulated in the container of the fragment. If you get a reference to the correct fragment and get a reference to the container you can call findViewById(R.id.someid).
Sample code:
// TODO cast checks
int item = mViewPager.getCurrentItem();
Fragment frag = (Fragment) mPagerAdapter.getItem(item);
View container = frag.getView();
TextView searchTextView = (TextView) container.findViewById(R.id.someid);
Or is your case:
// TODO add null + cast checks
TextView textView = (TextView) ((Fragment)adapter.getItem(0)).getView().findViewById(R.id.someText);
Hi i have a swipe pages example which contain 3 page and i want to add a List View to this example.
But when i try to run that eclipse say "Your content must have a ListView whose id attribute is 'android.R.id.list' ". i do not know whats wrong.
My Main Activity Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/customviewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Page1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue"
android:orientation="vertical" >
<Button
android:id="#+id/buttonBlue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/label_blue"
android:onClick="#string/listenerBlueButton" />
</LinearLayout>
Page2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/yellow"
android:orientation="vertical" >
<Button
android:id="#+id/buttonYellow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/label_yellow"
android:onClick="#string/listenerYellowButton" />
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Page 3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red"
android:orientation="vertical" >
<Button
android:id="#+id/buttonRed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/label_red"
android:onClick="#string/listenerRedButton" />
</LinearLayout>
My Pager Adapter
package ro.ovidiuconeac.horizontalviewswiping;
public class CustomPagerAdapter extends PagerAdapter {
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0: {
resId = R.layout.page_1;
break;
}
case 1: {
resId = R.layout.page_2;
break;
}
case 2: {
resId = R.layout.page_3;
break;
}
}
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
}
#Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
#Override
public Parcelable saveState() {
return null;
}
#Override
public int getCount() {
return 3;
}
}
Main Activity
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create and set adapter
CustomPagerAdapter adapter = new CustomPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.customviewpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(1);
String[] ex=new String[10];
ex[0]="1";
ex[1]="2";
ex[2]="3";
ex[3]="1";
ex[4]="2";
ex[5]="3";
ex[6]="1";
ex[7]="2";
ex[8]="3";
ex[9]="3";
setContentView(R.layout.page_2);
ListView myList=(ListView)findViewById(android.R.id.list);
ListAdapter la=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ex);
myList.setAdapter(la);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
/**
* Click button on blue page
*/
public void onClickBlueButton(View v) {
Toast.makeText(getApplicationContext(), "Blue screen", Toast.LENGTH_SHORT).show();
}
/**
* Click button on yellow page
*/
public void onClickYellowButton(View v) {
Toast.makeText(getApplicationContext(), "Yellow screen", Toast.LENGTH_SHORT).show();
}
/**
* Click button on red page
*/
public void onClickRedButton(View v) {
Toast.makeText(getApplicationContext(), "Red screen", Toast.LENGTH_SHORT).show();
}
}
This is because you're extending ListActivity. ListActivity looks for a ListView with a specific identifier from the android package.
Have a look at this line of your ListActivity
setContentView(R.layout.activity_main);
Your ListActivity is inflating the layout for your main activity, instead of the layout for your page 2(which contains your listview).
You need to change that line in the onCreate of your ListActivity to inflate the correct layout. Let's say your ListActivity layout is called R.layout.list_activy. That line then becomes
setContentView(R.layout.list_activity);
Instead of what you currently have, I'm not sure what the name of your layout file containing the listview is called you didn't mention it(page?).
EDIT: I just remembered that ListActivity may not need a call to setContentView() at all, since you pass in the parent layout to your adapter in setAdapter() anyways. Try removing that line altogether and just call setAdapter. Both of these approaches should work though
You have ListView in your XML but you are not passing your adapter to it. Create a ListView and pass your adapter to this list view.
Try this
ListView myList=(ListView)findViewById(android.R.id.list);
myList.setAdapter(la);