A fragment is not a Context. Pass in "getActivity()" instead of "this"
On Thu, Jul 23, 2015, 11:16 AM gvi70000 <gvi70...@gmail.com> wrote: > I have tried the following > > > <https://lh3.googleusercontent.com/-UwZUAdWZliQ/VbETW8LzhcI/AAAAAAAAIfk/KfACIlRyDZc/s1600/Untitled.png> > > //NameImg[][] list_NameImg = new NameImg[][]{basic, sensors, fastobjects, > pantilt, usb}; > ArrayList<NameImg[]> list_NameImg = new ArrayList<NameImg[]>(); > list_NameImg.add(basic); > list_NameImg.add(sensors); > list_NameImg.add(fastobjects); > list_NameImg.add(pantilt); > list_NameImg.add(usb); > ModesLvAdapter adapter = new ModesLvAdapter(this, R.layout.my_list, > list_NameImg.get(tab_idx)); > > > but now i get > > > > On Thursday, July 23, 2015 at 3:14:30 PM UTC+2, MagouyaWare wrote: > >> 1) What is the error you are getting? >> 2) What is ModesLvAdapter? You didn't provide that class. You basically >> gave us everything about your project except the ONE thing that has to do >> with your question. >> >> On Thu, Jul 23, 2015 at 5:56 AM gvi70000 <gvi7...@gmail.com> wrote: >> >> Here is how the UI should look like >> >> >> On Thursday, July 23, 2015 at 12:42:29 PM UTC+2, gvi70000 wrote: >> >> I would like to have your guidance to solve a problem that i have with my >> first android app (SlidingTabLayout) I have the following >> ViewPagerAdapter.java >> >> import android.support.v4.app.Fragment; >> import android.support.v4.app.FragmentManager; >> import android.support.v4.app.FragmentStatePagerAdapter; >> >> /** >> * Created by John on 6/12/2015. >> */ >> public class ViewPagerAdapter extends FragmentStatePagerAdapter { >> >> CharSequence Titles[]; // This will Store the Titles of the Tabs which >> are Going to be passed when ViewPagerAdapter is created >> int NumbOfTabs; // Store the number of tabs, this will also be passed >> when the ViewPagerAdapter is created >> >> >> // Build a Constructor and assign the passed Values to appropriate >> values in the class >> public ViewPagerAdapter(FragmentManager fm, CharSequence mTitles[], int >> mNumbOfTabsumb) { >> super(fm); >> >> this.Titles = mTitles; >> this.NumbOfTabs = mNumbOfTabsumb; >> >> } >> >> //This method return the fragment for the every position in the View >> Pager >> @Override >> public Fragment getItem(int position) { >> return Tab_Modes.init(position); >> } >> >> // This method return the titles for the Tabs in the Tab Strip >> >> @Override >> public CharSequence getPageTitle(int position) { >> return Titles[position]; >> } >> >> // This method return the Number of tabs for the tabs Strip >> >> @Override >> public int getCount() { >> return NumbOfTabs; >> } >> } >> >> >> The custom data structure class >> >> /** >> * Created by John on 7/22/2015. >> */ >> public class NameImg { >> public String itemName; >> public String itemDesc; >> public int itemImg; >> >> public NameImg() { >> super(); >> } >> >> public NameImg(String itemName, String itemDesc, int itemImg) { >> super(); >> this.itemName = itemName; >> this.itemDesc = itemDesc; >> this.itemImg = itemImg; >> } >> >> public String getName() { >> return this.itemName; >> } >> >> public void setName(String itemName) { >> this.itemName = itemName; >> } >> >> public String getDesc() { >> return this.itemDesc; >> } >> >> public void setDesc(String itemDesc) { >> this.itemDesc = itemDesc; >> } >> >> public int getImg() { >> return this.itemImg; >> } >> >> public void setImg(int itemImg) { >> this.itemImg = itemImg; >> } >> >> } >> >> >> and the tab >> >> /** >> * Created by John on 6/12/2015. >> */ >> public class Tab_Modes extends Fragment { >> int tab_idx; >> private ListView myLV; >> >> static Tab_Modes init(int val) { >> Tab_Modes myTab = new Tab_Modes(); >> // Supply val input as an argument. >> Bundle args = new Bundle(); >> args.putInt("val", val); >> myTab.setArguments(args); >> return myTab; >> } >> >> /** >> * Retrieving this instance's number from its arguments. >> */ >> >> public void onCreate(LayoutInflater inflater, ViewGroup container, >> Bundle savedInstanceState) { >> // super.onCreate(savedInstanceState); >> tab_idx = getArguments() != null ? getArguments().getInt("val") : 1; >> >> NameImg usb[] = new NameImg[] >> { >> new NameImg("1", "USB1", R.drawable.hand), >> new NameImg("2", "USB2", R.drawable.bulb), >> new NameImg("3", "USB3", R.drawable.bullet) >> }; >> NameImg[][] list_NameImg = new NameImg[][]{basic, spi, i2c, usb}; >> ModesLvAdapter adapter = new ModesLvAdapter(this, R.layout.my_list, >> list_NameImg[tab_idx][]); >> myLV = (ListView) myLV.findViewById(R.id.customListView); >> View v = inflater.inflate(R.layout.my_list, null); >> myLV.setAdapter(adapter); >> } >> } >> >> >> The activity_main.xml >> >> LinearLayout 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:orientation="vertical" >> tools:context=".MainActivity"> >> >> <include >> android:id="@+id/tool_bar" >> layout="@layout/tool_bar" >> android:layout_height="wrap_content" >> android:layout_width="match_parent" >> /> >> >> <com.grozeaion.www.gvicameraremotecontrol.SlidingTabLayout >> android:id="@+id/tabs" >> android:layout_width="match_parent" >> android:layout_height="wrap_content" >> android:elevation="2dp" >> android:background="@color/ColorPrimary"/> >> >> <android.support.v4.view.ViewPager >> android:id="@+id/pager" >> >> android:layout_height="match_parent" >> android:layout_width="match_parent" >> android:layout_weight="1" >> ></android.support.v4.view.ViewPager> >> >> </LinearLayout> >> >> >> tab_bodes.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"> >> >> >> <ListView >> android:id="@+id/customListView" >> android:layout_width="match_parent" >> android:layout_height="wrap_content" >> android:layout_alignParentLeft="true" >> android:layout_alignParentTop="true" > >> </ListView> >> </LinearLayout> >> >> >> >> and my_list.xml >> >> ... > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.