How to intent from Fragment Activity Class
going to a Fragment Class
?
the code below that i posted was used in an activity class where in there is a back button on the title bar.
now what i want to do is the same but i want to implement it in an fragment class
I tried this in my Activity Class..
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
and also
public boolean onOptionsItemSelected(MenuItem item){
Intent myIntent = new Intent(getApplicationContext(), LoginActivity.class);
startActivityForResult(myIntent, 0);
finish();
return true;
}
Try this
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
int id = item.getItemId();
switch(id)
{
case android.R.id.home:
// if (page == PAGE_CHILD) finish();
Intent myIntent = new Intent(getApplicationContext(), LoginActivity.class);
startActivityForResult(myIntent, 0);
finish();
break;
default:
break;
}
return true;
}
For fragments u can use
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.popBackStack();
at the place of Intent.
Or replace the fragments
LoginScreen firstFragment = new LoginScreen();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.article_fragment, firstFragment).commit();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.