I had created an app showing google map. its was created by extending Activity class. But Now i want the map to be shown onclick of a tab. This is my main activity class. I have created 3 tabs. I want to show map on click of 1st tab.
public class MainActivity extends FragmentActivity implements ActionBar.TabListener
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initilization
viewPager = (ViewPager) findViewById(R.id.pager);
actionBar = getActionBar();
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Adding Tabs
for (String tab_name : tabs)
{
actionBar.addTab(actionBar.newTab().setText(tab_name).setTabListener(this));
}
}
Here is code of map fragment
public class MapFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_map, container, false);
return rootView;
}
}
Here is code for fragment_map.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MapActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
class="com.google.android.gms.maps.MapFragment" />
<ProgressBar
android:id="@+id/speedbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/map"
android:layout_weight="1" />
<EditText
android:id="@+id/speed_text"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/speedbar"
android:ems="10"
android:enabled="false" >
<requestFocus />
</EditText>
when i execute above code it says
android.view.InflateException: Binary XML file line #9: Error inflating class fragment