listener for android spinner change activity

تعرفه تبلیغات در سایت
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس

آرشیو مطالب

جستجوگر

یافته ها در جستجو

    امکانات وب

    برچسب ها

    Vote count: 0

    i have a tabbed activity that has a spinner in its toolbar. I need to trigger changes in the tab fragments whenever the spinner value changes. I have so far implemented it by getting the spinner value from the fragment. However its not working as needed. I am new to listeners, is there any way i can do this with android callbacks. Any help would be appreciated.

    ExtensionActivity.java

    public class ExtensionActivity extends AppCompatActivity {
        private SectionsPageAdapter mSectionsPageAdapter;
        @BindView(R.id.container) ViewPager mViewPager;
        @BindView(R.id.tabs) TabLayout tabLayout;
        @BindView(R.id.toolbar) Toolbar toolbar;
        @BindView(R.id.spinner_nav) public Spinner cropsSpinner;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_extension);
            ButterKnife.bind(this);
    
            mSectionsPageAdapter = new SectionsPageAdapter(getFragmentManager());
            setupViewPager(mViewPager);
    
            tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
            tabLayout.setupWithViewPager(mViewPager);
    }
    
     private void setupViewPager(ViewPager viewPager){
            SectionsPageAdapter adapter  = new SectionsPageAdapter(getFragmentManager());
    
            adapter.addFragment(new ExtDescFragment(),"Description");
            adapter.addFragment(new ExtLandPFragment(),"Land Preparation");
    
            viewPager.setAdapter(adapter);
        }
    

    ExtDescFragment.java

    public class ExtDescFragment extends Fragment {
     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View view = inflater.inflate(R.layout.fragment_ext_desc, container, false);
            ButterKnife.bind(this,view);
            ((ExtensionActivity)getActivity()).cropsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView parent, View view, int position, long id) {
                    CROP =((ExtensionActivity)getActivity()).cp.get(position);
                    Log.e("CROP",CROP);
                    getCropInf();
                }
    
                @Override
                public void onNothingSelected(AdapterView parent) {
    
                }
            });
      }
    
    asked 1 min ago
    Izzo Obella

    نویسنده : استخدام کار بازدید : 0 تاريخ : جمعه 21 مهر 1396 ساعت: 23:07
    برچسب‌ها :