Domanda

Sono nuovo in Android, devo fare questa domanda.

Costruisco alcune applicazioni Android che implementano il talayout, quindi ogni attività è detenuta da ogni scheda della mia app. Ma prima, dovremmo affrontare l'attività di accesso.

La mia domanda è come posso logout quando siamo nell'attività della scheda e come posso aggiornarlo in ogni attività in quella scheda? Ho 3 schede e implevo il menu per "logout" e "aggiorna" e ho anche un menu per "about". Ecco il mio codice di esempio su TabActivity, ma impledo solo brindisi in ogni azione quando facciamo clic sul menu.

public class SampleTabActivity extends TabActivity {

private TabHost tabHost;
private Resources res;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.sipadutab);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    res = getResources(); // Resource object to get Drawables
    tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    tabHost.setCurrentTab(0);

    tabHost.setOnTabChangedListener(this); // set listener to tabhost IMPORTANT IMPORTANT

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, FirstActivity.class);
    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("first").setIndicator("First",
                      res.getDrawable(R.drawable.one))
                  .setContent(intent);
    tabHost.addTab(spec);       

    // Initialize a TabSpec for each tab and add it to the TabHost
    intent = new Intent().setClass(this, SecondActivity.class);
    spec = tabHost.newTabSpec("second").setIndicator("Second",
            res.getDrawable(R.drawable.two))
        .setContent(intent);
    tabHost.addTab(spec);

    // Initialize a TabSpec for each tab and add it to the TabHost
    intent = new Intent().setClass(this, ThirdActivity.class);
    spec = tabHost.newTabSpec("third").setIndicator("Third",
            res.getDrawable(R.drawable.three))
        .setContent(intent);
    tabHost.addTab(spec);



// Initiating Menu XML file (menu.xml)
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.layout.menuscreen, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item)
{

    switch (item.getItemId())
    {
    case R.id.menu_about:
        // Single menu item is selected do something
        // Ex: launching new activity/screen or show alert message
        Toast.makeText(SampleTabActivity.this, "About is Selected", Toast.LENGTH_SHORT).show();
        return true;

    case R.id.menu_refresh:
        Toast.makeText(SampleTabActivity.this, "Refresh is Selected", Toast.LENGTH_SHORT).show();
        return true;

    case R.id.menu_logout:
        Toast.makeText(SampleTabActivity.this, "Logout is Selected", Toast.LENGTH_SHORT).show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}   

}

Grazie in anticipo.

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top