我想将一个从一个选项卡传递到另一个选项卡的意图。当我在第一个片段中按下一个按钮时,我希望它引导我到另一个片段(例如活动)。是否有另一种方法可以在类似于 startActivity(new Intent(EntryTab.this, Journals.class)); 的片段中执行此操作 ? 下面是我的代码,startActivity 行显示错误。请帮忙!
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 * FROM entries", null);
c.moveToFirst();
// Log.i(LOGTAG, dr + " " + amt + " " + cr );// the last row
Log.i(LOGTAG, c.getString(0) + " " + c.getString(1) + " " + c.getString(2) );// shows always the first row
datasource.close();
startActivity(new Intent(EntryTab.this, Journals.class)); // error: the constructor intent is undefined.
}
});
return ll;
}
}