如何在android中缩短更改视图功能

时间:2014-08-04 12:03:59

标签: android performance android-layout

我有一个这样的功能。此方法的主要目的是在同一布局内切换布局以避免不同的活动

protected void SchermWisselen(int i) {
    if (i == -1) {
        this.finish();
    }
    if (i == OpstartScherm) {
        VorigeScherm = -1;
        // opstart scherm
        lblDLCKeuze.setVisibility(View.VISIBLE);
        listAparaatSelecteren.setVisibility(View.VISIBLE);
        btnRefresh.setVisibility(View.VISIBLE);
        // hoofdmenu scherm
        HOL.setVisibility(View.GONE);
        tglWissel.setVisibility(View.GONE);
        RGLijnen.setVisibility(View.GONE);
        btnMode.setVisibility(View.GONE);
        btnToonStatus.setVisibility(View.GONE);
        btnTijden.setVisibility(View.GONE);
        SKWaarde.setVisibility(View.GONE);
        txtStream.setVisibility(View.GONE);
        txtWaarde.setVisibility(View.GONE);
        txtInvoerWisselen.setVisibility(View.GONE);
        tglWissel.setVisibility(View.GONE);
        // Tijden versturen scherm
        txtZetTijd.setVisibility(View.GONE);
        txtUur.setVisibility(View.GONE);
        txtInvoerUur.setVisibility(View.GONE);
        txtMinuut.setVisibility(View.GONE);
        txtInvoerMinuut.setVisibility(View.GONE);
        txtLijn0.setVisibility(View.GONE);
        txtLijn1.setVisibility(View.GONE);
        SKLijn0.setVisibility(View.GONE);
        SKLijn1.setVisibility(View.GONE);
        spnNummerSelecteren.setVisibility(View.GONE);
        btnVerstTijd.setVisibility(View.GONE);
        btnMassa.setVisibility(View.GONE);
        // Discovery scherm
        btnDiscoveryZoeken.setVisibility(View.GONE);
        lvDiscoveryResultaten.setVisibility(View.GONE);
        lblDiscoveryTonen.setVisibility(View.GONE);
        // Commando Sturen
        txtCommandosInvoer.setVisibility(View.GONE);
        txtCommandoUitvoer.setVisibility(View.GONE);
        // Status tonen
        btnSyncKlok.setVisibility(View.GONE);
        btnSyncDag.setVisibility(View.GONE);
        btnCommando.setVisibility(View.GONE);
        btnParameters.setVisibility(View.GONE);
        btnGrafiek.setVisibility(View.GONE);
        btnAstroData.setVisibility(View.GONE);
        txtToonStatus.setVisibility(View.GONE);
        // grafiek
        lnGrafiek.setVisibility(View.GONE);
    }
    if (i == HoofdMenu) {
        VorigeScherm = -1;
        //brute force
        GeOpend = false;
        // opstart scherm
        lblDLCKeuze.setVisibility(View.GONE);
        listAparaatSelecteren.setVisibility(View.GONE);
        btnRefresh.setVisibility(View.GONE);
        // hoofdmenu scherm
        HOL.setVisibility(View.VISIBLE);
        tglWissel.setVisibility(View.VISIBLE);
        RGLijnen.setVisibility(View.VISIBLE);
        btnMode.setVisibility(View.VISIBLE);
        btnToonStatus.setVisibility(View.VISIBLE);
        btnTijden.setVisibility(View.VISIBLE);
        SKWaarde.setVisibility(View.GONE);
        txtStream.setVisibility(View.VISIBLE);
        txtWaarde.setVisibility(View.VISIBLE);
        txtInvoerWisselen.setVisibility(View.VISIBLE);
        // Tijden versturen scherm
        txtZetTijd.setVisibility(View.GONE);
        txtUur.setVisibility(View.GONE);
        txtInvoerUur.setVisibility(View.GONE);
        txtMinuut.setVisibility(View.GONE);
        txtInvoerMinuut.setVisibility(View.GONE);
        txtLijn0.setVisibility(View.GONE);
        txtLijn1.setVisibility(View.GONE);
        SKLijn0.setVisibility(View.GONE);
        SKLijn1.setVisibility(View.GONE);
        spnNummerSelecteren.setVisibility(View.GONE);
        btnVerstTijd.setVisibility(View.GONE);
        btnMassa.setVisibility(View.GONE);
        // Discovery scherm
        btnDiscoveryZoeken.setVisibility(View.GONE);
        lvDiscoveryResultaten.setVisibility(View.GONE);
        lblDiscoveryTonen.setVisibility(View.GONE);
        // Commando Sturen
        txtCommandosInvoer.setVisibility(View.GONE);
        txtCommandoUitvoer.setVisibility(View.GONE);
        // Status tonen
        btnSyncKlok.setVisibility(View.GONE);
        btnSyncDag.setVisibility(View.GONE);
        btnCommando.setVisibility(View.GONE);
        btnParameters.setVisibility(View.GONE);
        btnGrafiek.setVisibility(View.GONE);
        btnAstroData.setVisibility(View.GONE);
        txtToonStatus.setVisibility(View.GONE);
        // grafiek
        lnGrafiek.setVisibility(View.GONE);
    }

这感觉就像很多漂洗和重复一样,并没有那么好。

1 个答案:

答案 0 :(得分:0)

您可以将要隐藏的所有视图放入一个容器中,例如带有ID的FrameLayout,然后隐藏该ID。

但我真的会推荐像片段这样的另一种方法(旧版本有支持片段管理器)。