Java - cambiar de imagen y calcular varios problemas con spinner

 
Vista:
sin imagen de perfil

cambiar de imagen y calcular varios problemas con spinner

Publicado por liantony (6 intervenciones) el 07/04/2017 01:23:14
hola , estoy intentando que con un spinner con la seleccion en el spinner cambie la imagen en el activity y el problema matematico que se realizara en la aplicacion , pero tengo problema en como hacer que mi metodo onclick hacer un swich con 4 casos en el spinner junto con el cambio de imagen


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.example.liantonypozo.calculosmatematicos3;
 
import android.content.Intent;
import android.content.res.TypedArray;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
 
public class AnguloReferencia extends AppCompatActivity {
 
 
    EditText ar1;
    TextView tex1 , tex2,tex3;
 
    private String[] listOfObjects;
 
    private TypedArray images;
 
    private ImageView itemImage;
 
 
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_angulo_referencia);
 
        listOfObjects = getResources().getStringArray(R.array.object_array);
        images = getResources().obtainTypedArray(R.array.object_image);
 
 
        itemImage = (ImageView)findViewById(R.id.imageviewar);
 
        final Spinner spinner = (Spinner)findViewById(R.id.spinnerar);
 
        ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_item, listOfObjects);
 
        spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinnerAdapter);
 
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
 
 
 
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
 
                itemImage.setImageResource(images.getResourceId(spinner.getSelectedItemPosition(), -1));
 
            }
 
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
 
            }
        });
 
 
 
 
        ar1 = (EditText)findViewById(R.id.anguloReferenciaEditText);
     tex1 = (TextView)  findViewById(R.id.anguloReferenciatext1);
     tex2 = (TextView)  findViewById(R.id.anguloReferenciatext2);
     tex3 = (TextView)  findViewById(R.id.anguloReferenciatext3);
 
 
     /*   Button button = (Button)findViewById(R.id.pasosAnguloReferencia);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(v.getContext() , HipotenusaEjemplo.class);
                startActivityForResult(intent ,0);
            }
        });*/
 
 
 
 
    }
 
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
 
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
 
        int id = item.getItemId();
 
        if (id == R.id.action_settings) {
            return true;
 
 
        }
        return super.onOptionsItemSelected(item);
    }
 
 
 
 
 
    public  void  calcular4 (View v){
 
        double ar_1 = Double.parseDouble(ar1.getText().toString());
 
 
 
        tex1.setText("AR=180˚- AC");
 
        tex2.setText("AR=180˚-"+ar_1+"˚");
 
        double resu = (180 - ar_1) ;
        double ar= Double.valueOf(resu);
 
        tex3.setText("AR="+ ar +"˚");
 
 
 
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 349
Bronce
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

cambiar de imagen y calcular varios problemas con spinner

Publicado por Andrés (340 intervenciones) el 08/04/2017 18:31:56
Puedes compartir el android project?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar