Pass intents between fragments -


i want pass intent 1 tab another. when press button in first fragment want direct me other fragment ( such activities). there way in fragments similar startactivity(new intent(entrytab.this, journals.class)); ? below code , startactivity line shows error. please!

public class entrytab extends fragment{     public static final string logtag = "balance";     @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         final linearlayout ll = (linearlayout) inflater.inflate(r.layout.entries, container, false);         button save = (button) ll.findviewbyid(r.id.entriesbutton);         save.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                  balanceapp myapp= (balanceapp) getactivity().getapplicationcontext();                 datasource datasource = myapp.datasource;                 datasource.open();                  log.i(logtag,"inside tab entry");                  edittext amount = (edittext) ll.findviewbyid(r.id.amount);                 int amt = integer.parseint(amount.gettext().tostring());                   edittext debit = (edittext)ll.findviewbyid(r.id.debittext);                  string dr = debit.gettext().tostring();                   edittext credit = (edittext)ll.findviewbyid(r.id.credittext);                  string cr = credit.gettext().tostring();                   datasource.createentry(dr, "dr", amt);                  datasource.createentry(cr, "cr", amt);                   cursor c=datasource.database.rawquery("select * entries", null);                  c.movetofirst();               //   log.i(logtag, dr + " " + amt + " " + cr );// last row                   log.i(logtag, c.getstring(0) + " " + c.getstring(1) + " " + c.getstring(2) );// shows first row                  datasource.close();                   startactivity(new intent(entrytab.this, journals.class)); // error: constructor intent undefined.          }     });     return ll;       } } 

an activity can have many fragments. in fragment can the activity getactivity() method.

moreover, go activity -> activity b use intents. likewise, go fragment -> fragment b, in activity a, use fragmenttransactions.

fragmenttransaction fragmenttransaction = getsupportfragmentmanager().begintransaction(); fragment f = new customfragment(); fragmenttransaction.add(r.id.fragment_container, f); fragmenttransaction.commit(); 

also, use addtobackstack() method, in order return fragment fragment b on backpress.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -