如何从导航抽屉更改TabLayout的选项卡

时间:2015-12-13 05:18:05

标签: java android android-fragments navigation-drawer

目前我正在更改NavigationDrawer中的标签但这不是一种正确的方式而且从NavigationDrawer更改标签需要很长时间,因为我更换了主要{{}每次都有{1}}个标签,我不想要它。更多

NavigationDrawerAdapter.java

Fragment

MainActivity.java

public class NavDrawerListAdapter extends BaseAdapter {

public Context context;
public MainActivity activity;
public MainTabFragment fragment;
int currentSelectedPostion;
LayoutInflater mInflater;
TextView tv_signup;
SharedPreferences share;
boolean cbc = false;
String fis = "", las = "";
int group_id = 0;
private String[] titles;
private int[] images;
private int[] selectedposition;

public NavDrawerListAdapter(Context context, int[] selectedposition, boolean cb, String fis, String las) {
    this.context = context;
    this.images = images;
    this.cbc = cb;
    this.fis = fis;
    this.las = las;
    share = context.getSharedPreferences("sharePref", 0);
    group_id = share.getInt("group_id", 0);
    this.selectedposition = selectedposition;
    mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

}

@Override
public int getCount() {
    return 1;
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(com.cws.advisorymandi.R.layout.drawer_list_item, null);
    }
    LinearLayout ll_contact_us = (LinearLayout) convertView.findViewById(com.cws.advisorymandi.R.id.contact_item);
    RelativeLayout ll_login = (RelativeLayout) convertView.findViewById(com.cws.advisorymandi.R.id.signup_item);
    LinearLayout ll_equity = (LinearLayout) convertView.findViewById(com.cws.advisorymandi.R.id.equity_item);
    LinearLayout ll_indices = (LinearLayout) convertView.findViewById(com.cws.advisorymandi.R.id.indices_item);

    if (cbc) {
        tv_signup.setText("Welcome " + fis + " " + las);
        tv_logout.setVisibility(View.VISIBLE);
        tv_edit.setVisibility(View.VISIBLE);
    }
    ll_equity.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MainActivity.getInstance().displayView(3, 0, 0);
        }
    });
    ll_indices.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                 MainActivity.getInstance().displayView(3, 0, 1);
        }
    });
    });
    return convertView;
}

}

public class MainActivity extends AppCompatActivity { public ListView mDrawerList; NavDrawerListAdapter adapter; public static MainActivity getInstance() { return sMainActivity; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(com.cws.advisorymandi.R.layout.activity_main) mDrawerList = (ListView) findViewById(com.cws.advisorymandi.R.id.list_slidermenu); adapter = new NavDrawerListAdapter(getApplicationContext(), selectedposition, cb, firstName, lastName); mDrawerList.setAdapter(adapter); } /** * Diplaying fragment view for selected nav drawer list item */ public int displayView(int position, int position2, int position3) { // update the main content by replacing fragments first_position = position; second_position = position2; third_position = position3; fragment = null; switch (position) { case 0: sharedPreferences = getSharedPreferences("sharePref", 0); cb = sharedPreferences.getBoolean("ConfirmLogin", false); if (cb) { } else new Handler().postDelayed(new Runnable() { @Override public void run() { fragment = new LoginActivity(); changeFragments3(); } }, 150); mDrawerLayout.closeDrawer(mDrawerList); break; case 3: // fragment = new MainTabFragment(); /* new Handler().postDelayed(new Runnable() { @Override public void run() {*/ fragment = new MainTabFragment(); changeFragments(); /*} }, 150); mDrawerLayout.closeDrawer(mDrawerList);*/ break; } return 0; } }

0 个答案:

没有答案