尝试更新我的标签内容

时间:2016-04-26 02:57:22

标签: android tabs updates

我正在使用tablayout,我想在用户点击标签时更新标签内容。基本上我想做标签在创建时所做的事情(检查数据库中的内容并将其放在我的列表视图中)。

这是我的MainActivity:

User   Total   moto    car     
------------------------------
danny  15.000  2        1       

这是我的ViewPageradapter:

 public class MainActivity extends AppCompatActivity{
        // Declaring Your View and Variables
        Toolbar toolbar;
        ViewPager viewPager;
        ViewPagerAdapter adapter;
        TabLayout tabLayout;
        CharSequence Titles[]={"Participantes","Torneio","Classificação"};
        int Numboftabs =3;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            toolbar = (Toolbar) findViewById(R.id.tool_bar);
            viewPager = (ViewPager) findViewById(R.id.viewPager);
            tabLayout = (TabLayout)findViewById(R.id.tabLayout);


            // Creating The Toolbar and setting it as the Toolbar for the activity
            setSupportActionBar(toolbar);
            // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
            adapter =  new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);
            // Assigning ViewPager View and setting the adapter
            viewPager.setAdapter(adapter);


            tabLayout.setupWithViewPager(viewPager);
            tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.colorTextIcons));
            tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                @Override
                public void onTabSelected(TabLayout.Tab tab) {
                    adapter.notifyDataSetChanged();
                }


                @Override
                public void onTabUnselected(TabLayout.Tab tab) {

                }

                @Override
                public void onTabReselected(TabLayout.Tab tab) {

                }
            });
        }

        @Override
        protected void onDestroy() {
            super.onDestroy();
            viewPager = null;
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();

            //noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
            if (id == R.id.action_info) {
                Toast.makeText(getApplicationContext(), "Contacto: Juniortalisson16@gmail.com", Toast.LENGTH_LONG).show();
                return true;
            }
            return super.onOptionsItemSelected(item);
        }


    }

我尝试使用getItemPosition,但它不起作用,当我选择一个标签时,我的应用程序崩溃。

任何想法?请

0 个答案:

没有答案