如何通过另一个 activity 中的意图打开片段 class?
How to open fragment class through intent in another activity?
我的 SlidingScreenActivity 代码是,
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
public void displayView(int position) {
Fragment fragment = null;
switch (position) {
case 0:
mDrawerLayout.closeDrawer(mDrawerList);
break;
case 1:
fragment=new HomeFragment();
break;
case 2:
fragment=new Mywallet();
break;
case 3:
fragment=new AboutUsFragment();
break;
default:
break;
}
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.closeDrawer(mDrawerList);
Log.e("SlidingMainActivity", "Error in creating fragment");
}
}
另一个 Activity 按钮侦听器,
btnWallet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent=new Intent(this,SlidingScreenActivity.class);
startActivity(mIntent);
}
});
如何打开MyWallet fragment
我已经在案例 2 中声明的:在 SlidingScreenActivity.class
中,当通过 Intent 单击另一个 activity 中的按钮时?
谁能帮帮我?
提前致谢...
滑动屏幕Activity:
@Override
protected void onStart() {
super.onStart();
displayView(getIntent().getIntExtra("position", 2));
}
另一个 Activity 按钮侦听器:
btnWallet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent=new Intent(this,SlidingScreenActivity.class);
intent.putExtra("position", 2);
startActivity(mIntent);
}
});
我的 SlidingScreenActivity 代码是,
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
public void displayView(int position) {
Fragment fragment = null;
switch (position) {
case 0:
mDrawerLayout.closeDrawer(mDrawerList);
break;
case 1:
fragment=new HomeFragment();
break;
case 2:
fragment=new Mywallet();
break;
case 3:
fragment=new AboutUsFragment();
break;
default:
break;
}
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
mDrawerLayout.closeDrawer(mDrawerList);
Log.e("SlidingMainActivity", "Error in creating fragment");
}
}
另一个 Activity 按钮侦听器,
btnWallet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent=new Intent(this,SlidingScreenActivity.class);
startActivity(mIntent);
}
});
如何打开MyWallet fragment
我已经在案例 2 中声明的:在 SlidingScreenActivity.class
中,当通过 Intent 单击另一个 activity 中的按钮时?
谁能帮帮我?
提前致谢...
滑动屏幕Activity:
@Override
protected void onStart() {
super.onStart();
displayView(getIntent().getIntExtra("position", 2));
}
另一个 Activity 按钮侦听器:
btnWallet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent mIntent=new Intent(this,SlidingScreenActivity.class);
intent.putExtra("position", 2);
startActivity(mIntent);
}
});