您好,登錄后才能下訂單哦!
public class MainActivity extendsFragmentActivity
{
private ListView mListView; // 菜單listview
public DrawerLayout mDrawrLayut;
private RelativeLayout mSildingMenu; // 菜單布局
private MyAdapter mMyAdapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUI();
mMyAdapter = new MyAdapter(this);
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);//listview刷新
mListView.setOnItemClickListener(new DrawerItemClickListener());
mListView.setAdapter(mMyAdapter);
}
private class DrawerItemClickListener implements
ListView.OnItemClickListener
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id)
{
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
Fragment myFragment = null;
switch (position)
{
// 點擊不同item加載不同的ragment
case 0:
myFragment = new ShouYeFragment("首頁", mTvTitle);
break;
case 1:
myFragment = new ShouYeFragment("首頁", mTvTitle);
break;
case 2:
myFragment = new ShouYeFragment("首頁", mTvTitle);
break;
case 3:
myFragment = new ShouYeFragment("首頁", mTvTitle);
break;
default:
break;
}
curr_pos = position;
mMyAdapter.notifyDataSetChanged(); //listview刷新
ft.replace(R.id.content, myFragment);
// ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// //設置add按back可以跳到上一個fragment
// ft.addToBackStack(null);
ft.commit();
mDrawrLayut.closeDrawer(mSildingMenu);
}
}
private void initUI()
{
mDrawrLayut = (DrawerLayout) findViewById(R.id.drawer_layout);
mSildingMenu = (RelativeLayout) findViewById(R.id.sildingmenu);
mListView = (ListView) mSildingMenu.findViewById(R.id.listView1);
findViewById(R.id.iv_back).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
mDrawrLayut.openDrawer(mSildingMenu);
}
});
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。