Aditya Vyas - Lakhan Aditya Vyas - Lakhan - 4 months ago 41
Android Question

How to set images in tabhost using fragment

I have navigation drawer from this example..now when i run the application first item of drawer is appearing

In my fragment i added Tabhost,in my Tabhost i am able to set text,but i want to put images instead of text

following is my code can any one help

public class HomeFragment extends Fragment {

ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;

private FragmentTabHost tabHost;
private SearchView searchView;

public HomeFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

tabHost = new FragmentTabHost(getActivity());
tabHost.setup(getActivity(), getChildFragmentManager(), R.layout.my_parent_fragment);

Bundle arg1 = new Bundle();
arg1.putInt("Arg for Frag1", 1);


// tabHost.newTabSpec("All").setIndicator(null,getResources().getDrawable(R.drawable.ic_launcher)).setContent(R.id.tab_template_two_tabs_all);

// tabHost.addTab(tabHost.newTabSpec("one").setIndicator("The Tab", getResources().getDrawable(R.drawable.ic_launcher)).setContent(new Intent(getActivity(), DiscoverFragment.class)));
tabHost.addTab(tabHost.newTabSpec("First").setIndicator("First"), DiscoverFragment.class, arg1);

// tabHost.addTab(tabHost.newTabSpec("TAb1").setIndicator("Tab1"),FragmentA.class,arg1);

Bundle arg2 = new Bundle();
arg2.putInt("Arg for Frag2", 2);
tabHost.addTab(tabHost.newTabSpec("Sec").setIndicator("Sec"), ShopFragment.class, arg2);

Bundle arg3 = new Bundle();
arg2.putInt("Arg for Frag3", 3);
tabHost.addTab(tabHost.newTabSpec("Third").setIndicator("Third"), Thirdtab.class, arg3);

Bundle arg4 = new Bundle();
arg2.putInt("Arg for Frag4", 4);
tabHost.addTab(tabHost.newTabSpec("Four").setIndicator("Four"), FourthTabs.class, arg4);
return tabHost;


}


}


xml

<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

</android.support.v4.app.FragmentTabHost>

Answer
spec = tabHost.newTabSpec("First").setIndicator("name",getResources().getDrawable(R.drawable.port))
                    .setContent(intent);

Try it.

Comments