I use View Pager to display three views.
"Filter","Streets","Around"
Each species is identified by a fragment.
WHAT I WANT: I want to use Mapview Inside My FilterFragment.
WHAT I'VE DONE:
I want to use the MapView Inside filter fragment, but could not successfully execute it. and Error receiving log:
android.view.InflateException: Binary XML file line #33: Error inflating class com.google.android.maps.MapView
I also searched Net and Stackoverflow about this problem and found LINK and LINK , but I could not find the link related to my problem, because I am using a snippet with ViewPager.
I put my code below.
Here is my code for MainViewPager.java:
package com.example.viewpageractivitydemo; import com.example.viewpageractivitydemo.viewpager.TitlePageIndicator; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewPager; import android.util.Log; public class MainViewPager extends FragmentActivity { TestFragmentAdapter adapter; ViewPager pager; @Override protected void onCreate(Bundle arg0) {
Here is the code for TestFragmentAdapter.java
package com.example.viewpageractivitydemo; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.util.Log; public class TestFragmentAdapter extends FragmentPagerAdapter { protected static final String[] CONTENT = new String[] { "Filter", "Streets", "Around" }; public String TAG = "TestFragmentAdapter"; private int mCount = CONTENT.length; public TestFragmentAdapter(FragmentManager fm) { super(fm); // TODO Auto-generated constructor stub } @Override public Fragment getItem(int position) { // TODO Auto-generated method stub Log.i(TAG, "Inside getItemMethod with position " + position); if (position == 0) { Log.i("TestFragmentAdapter","Inside if Condition"); return FilterFragment.newInstance(position); } else if (position == 1) { return StreetsFragment.newInstance(position); } else if (position == 2) { return AroundFragment.newInstance(position); } else { return null; } // return MainFragment.newInstance(CONTENT[position % CONTENT.length]); } @Override public int getCount() { // TODO Auto-generated method stub return mCount; } public void setCount(int count) { if (count > 0 && count <= 10) { mCount = count; notifyDataSetChanged(); } } }
Here is my code for FilterFragment.java:
package com.example.viewpageractivitydemo; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class FilterFragment extends Fragment { public static Fragment newInstance(int position) { Log.i("FilterFragment","Inside New Instasnce"); FilterFragment filterFragment = new FilterFragment(); return filterFragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Here is my code for filter.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="fill_parent" android:background="#C6CDD4" android:gravity="center" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#93A4BA" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_margin="5dp" android:gravity="center" android:text="Where Am I" android:textColor="#ffffff" android:textSize="18dp" android:textStyle="bold" > </TextView> </LinearLayout> <com.google.android.maps.MapView android:id="@+id/whereami_mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:apiKey="0-PaH6rk7RKrZSMd_lqdrZi6FazYyIlX5r6YFyA" android:clickable="true" /> </LinearLayout> </LinearLayout>
Can anyone suggest me an answer to a solution to my problem. I spent many hours on this. Still not getting any idea about my Question. Thnks in Advance.