lundi 7 décembre 2015

How can a menu item in my activity get data from the tabs(view pager fragments)?

I have an activity that has 4 tabs(view pager fragments). The fragments have forms in them, edittexts to record information. I would like to use a menu item in my activity to save the information to a database and to also create a pdf file. The file creates alright but no information is passed into it and it returns an I/O error. I believe the database has been created too but no information gets stored in it. I get a null.

public void save_final(){

    Serv_BaseDataFragment baseFragment = (Serv_BaseDataFragment)getSupportFragmentManager().findFragmentById(R.id.baseDataTab);
    baseFragment.serv_insertToBaseData_db();

    ServicingFragment serviceFragment = (ServicingFragment)getSupportFragmentManager().findFragmentById(R.id.servicingTab);
    serviceFragment.insertToServicing_db();

    ReplacementFragment replaceFragment = (ReplacementFragment)getSupportFragmentManager().findFragmentById(R.id.baseDataTab);
    replaceFragment.insertToReplacement_db();

    Toast.makeText(this, "ALL DATA STORED SUCCESSFULLY", Toast.LENGTH_LONG).show();
    Intent intent = getIntent();
    finish();
    startActivity(intent);


}

public void writePdf(){
    String filename = Serv_BaseDataFragment.sysaid.getText().toString();

    Serv_CreatePDF fop = new Serv_CreatePDF();

    if (fop.writepdf(filename)) {
        Toast.makeText(getApplicationContext(), filename +  ".pdf created", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(), "I/O error", Toast.LENGTH_SHORT).show();
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_maintenance, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        Intent intent = new Intent(this, Serv_SettingsActivity.class);
        startActivity(intent);
        return true;
    }
    if (id == R.id.save_tickets) {
        save_final();
        writePdf();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

Aucun commentaire:

Enregistrer un commentaire