第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

活動(dòng)開始時(shí)加載片段

活動(dòng)開始時(shí)加載片段

守著星空守著你 2023-09-27 16:52:29
我正在按照一個(gè)博客的教程來創(chuàng)建片段。我創(chuàng)建了三個(gè)片段,但是當(dāng) Mainactivity 加載時(shí)......它是空的,并且只有當(dāng)單擊抽屜菜單中的任何項(xiàng)目時(shí),才會(huì)加載片段。我想在開始時(shí)加載任何片段[考慮 ConnectFragment]。這是我的代碼public class MainActivity extends AppCompatActivity {    private String[] mNavigationDrawerItemTitles;    private DrawerLayout mDrawerLayout;    private ListView mDrawerList;    Toolbar toolbar;    private CharSequence mDrawerTitle;    private CharSequence mTitle;    android.support.v7.app.ActionBarDrawerToggle mDrawerToggle;    Fragment fragment = null;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mTitle = mDrawerTitle = getTitle();        mNavigationDrawerItemTitles= getResources().getStringArray(R.array.navigation_drawer_items_array);        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);        mDrawerList = (ListView) findViewById(R.id.left_drawer);        setupToolbar();        fragment = new ConnectFragment();        DataModel[] drawerItem = new DataModel[3];        drawerItem[0] = new DataModel(R.drawable.connect, "Connect");        drawerItem[1] = new DataModel(R.drawable.fixtures, "Fixtures");        drawerItem[2] = new DataModel(R.drawable.table, "Table");        getSupportActionBar().setDisplayHomeAsUpEnabled(false);        getSupportActionBar().setHomeButtonEnabled(true);        DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.list_view_item_row, drawerItem);        mDrawerList.setAdapter(adapter);        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);        mDrawerLayout.setDrawerListener(mDrawerToggle);        setupDrawerToggle();    }我嘗試過            fragment = new ConnectFragment();但它仍然在開始時(shí)不加載。提前致謝。
查看完整描述

1 回答

?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊

不需要?jiǎng)?chuàng)建fragment實(shí)例,onCreate您可以刪除以下行


fragment = new ConnectFragment();

簡而言之,您應(yīng)該像下面這樣調(diào)用selectItem()內(nèi)部方法。onCreate()


@Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // .....

        setupDrawerToggle();

        // here you need call selectItem() method 

        selectItem(0) // you can change default fragment by changing parameter (0/1/2) as you want

    }


查看完整回答
反對(duì) 回復(fù) 2023-09-27
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)