C
C
Chvalov2016-03-21 15:34:41
Android
Chvalov, 2016-03-21 15:34:41

Is there a more correct way to work with Android elements?

Is there a more compact way to write code like this:

public class ActivitySettings extends AppCompatActivity{

    TextView TV_CP30_PhaseA, TV_CP30_PhaseB, TV_CP30_PhaseC, TV_BC_PhaseA, TV_BC_PhaseB, TV_BC_PhaseC, TV_UUZ_PhaseA, TV_UUZ_PhaseB,
            TV_UUZ_PhaseC,TV_PZS_PhaseA, TV_PZS_PhaseB, TV_PZS_PhaseC, TV_ZOA_PhaseA, TV_ZOA_PhaseB, TV_ZOA_PhaseC, TV_ZRK_PhaseA,
            TV_ZRK_PhaseB, TV_ZRK_PhaseC,TV_VS13_PhaseA, TV_VS13_PhaseB, TV_VS13_PhaseC, TV_VS46_PhaseA, TV_VS46_PhaseB,
            TV_VS46_PhaseC, TV_ZOM_PhaseA, TV_ZOM_PhaseB, TV_ZOM_PhaseC;
    EditText ET_CP30_SensorType, ET_BC_SensorType, ET_UUZ_SensorType, ET_PZS_SensorType, ET_ZOA_SensorType, ET_ZRK_SensorType,
            ET_VS13_SensorType, ET_VS46_SensorType, ET_ZOM_SensorType, ET_CP30_Inom, ET_BC_Inom, ET_UUZ_Inom, ET_PZS_Inom,
            ET_ZOA_Inom, ET_ZRK_Inom, ET_VS13_Inom, ET_VS46_Inom, ET_ZOM_Inom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ET_CP30_SensorType = (EditText) findViewById(R.id.ET_CP30_SensorType);
        ET_BC_SensorType = (EditText) findViewById(R.id.ET_BC_SensorType);
        ET_UUZ_SensorType = (EditText) findViewById(R.id.ET_UUZ_SensorType);
        ET_PZS_SensorType = (EditText) findViewById(R.id.ET_PZS_SensorType);
        ET_ZOA_SensorType = (EditText) findViewById(R.id.ET_ZOA_SensorType);
        ET_ZRK_SensorType = (EditText) findViewById(R.id.ET_ZRK_SensorType);
        ET_VS13_SensorType = (EditText) findViewById(R.id.ET_VS13_SensorType);
        ET_VS46_SensorType = (EditText) findViewById(R.id.ET_VS46_SensorType);
        ET_ZOM_SensorType = (EditText) findViewById(R.id.ET_ZOM_SensorType);
        ET_CP30_Inom = (EditText) findViewById(R.id.ET_CP30_Inom);
        ET_BC_Inom = (EditText) findViewById(R.id.ET_BC_Inom);
        ET_UUZ_Inom = (EditText) findViewById(R.id.ET_UUZ_Inom);
        ET_PZS_Inom = (EditText) findViewById(R.id.ET_PZS_Inom);
        ET_ZOA_Inom = (EditText) findViewById(R.id.ET_ZOA_Inom);
        ET_ZRK_Inom = (EditText) findViewById(R.id.ET_ZRK_Inom);
        ET_VS13_Inom = (EditText) findViewById(R.id.ET_VS13_Inom);
        ET_VS46_Inom = (EditText) findViewById(R.id.ET_VS46_Inom);
        ET_ZOM_Inom = (EditText) findViewById(R.id.ET_ZOM_Inom);
        TV_CP30_PhaseA = (TextView) findViewById(R.id.TV_CP30_PhaseA);
        TV_CP30_PhaseB = (TextView) findViewById(R.id.TV_CP30_PhaseB);
        TV_CP30_PhaseC = (TextView) findViewById(R.id.TV_CP30_PhaseC);
        TV_BC_PhaseA = (TextView) findViewById(R.id.TV_BC_PhaseA);
        TV_BC_PhaseB = (TextView) findViewById(R.id.TV_BC_PhaseB);
        TV_BC_PhaseC = (TextView) findViewById(R.id.TV_BC_PhaseC);
        TV_UUZ_PhaseA = (TextView) findViewById(R.id.TV_UUZ_PhaseA);
        TV_UUZ_PhaseB = (TextView) findViewById(R.id.TV_UUZ_PhaseB);
        TV_UUZ_PhaseC = (TextView) findViewById(R.id.TV_UUZ_PhaseC);
        TV_PZS_PhaseA = (TextView) findViewById(R.id.TV_PZS_PhaseA);
        TV_PZS_PhaseB = (TextView) findViewById(R.id.TV_PZS_PhaseB);
        TV_PZS_PhaseC = (TextView) findViewById(R.id.TV_PZS_PhaseC);
        TV_ZOA_PhaseA = (TextView) findViewById(R.id.TV_ZOA_PhaseA);
        TV_ZOA_PhaseB = (TextView) findViewById(R.id.TV_ZOA_PhaseB);
        TV_ZOA_PhaseC = (TextView) findViewById(R.id.TV_ZOA_PhaseC);
        TV_ZRK_PhaseA = (TextView) findViewById(R.id.TV_ZRK_PhaseA);
        TV_ZRK_PhaseB = (TextView) findViewById(R.id.TV_ZRK_PhaseB);
        TV_ZRK_PhaseC = (TextView) findViewById(R.id.TV_ZRK_PhaseC);
        TV_VS13_PhaseA = (TextView) findViewById(R.id.TV_VS13_PhaseA);
        TV_VS13_PhaseB = (TextView) findViewById(R.id.TV_VS13_PhaseB);
        TV_VS13_PhaseC = (TextView) findViewById(R.id.TV_VS13_PhaseC);
        TV_VS46_PhaseA = (TextView) findViewById(R.id.TV_VS46_PhaseA);
        TV_VS46_PhaseB = (TextView) findViewById(R.id.TV_VS46_PhaseB);
        TV_VS46_PhaseC = (TextView) findViewById(R.id.TV_VS46_PhaseC);
        TV_ZOM_PhaseA = (TextView) findViewById(R.id.TV_ZOM_PhaseA);
        TV_ZOM_PhaseB = (TextView) findViewById(R.id.TV_ZOM_PhaseB);
        TV_ZOM_PhaseC = (TextView) findViewById(R.id.TV_ZOM_PhaseC);
        
        setContentView(R.layout.activity_settings);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2016-03-21
@onepavel

jakewharton.github.io/butterknife
and a dozen more ways and options
developer.android.com/intl/ru/tools/data-binding/g...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question