Android - PROBLEMA CON LISTVIEWS

 
Vista:
sin imagen de perfil

PROBLEMA CON LISTVIEWS

Publicado por Alfredo (7 intervenciones) el 22/01/2017 13:16:35
ESTOY HACIENDO UNA CALCULADORA COMO ACTIVIDAD DE PRACTICA, Y NO SE COMO A CADA ELEMENTO DE LA LISTA PUEDO PONERLE UN SUBTITULO DE MODO QUE QUEDE ASI:

+
sumar

-
restar

X
multiplicar

%
dividir


Tengo este codigo en mi java:


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
package com.example.pepe.calculadora_sub;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
 
import static com.example.pepe.calculadora_sub.R.id.operaciones;
 
public class MainActivity extends AppCompatActivity {
    private EditText numero1,numero2;
    private TextView resum,reres,remul,rediv,textito;
    private ListView operaciones;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        numero1=(EditText)findViewById(R.id.numero1);
        numero2=(EditText)findViewById(R.id.numero2);
        resum=(TextView)findViewById(R.id.resum);
        reres=(TextView)findViewById(R.id.reres);
        remul=(TextView)findViewById(R.id.remul);
        rediv=(TextView)findViewById(R.id.rediv);
        textito=(TextView)findViewById(R.id.textito);
        operaciones=(ListView)findViewById(R.id.operaciones);
        String [] opciones={"+","-","X","%"};
        ArrayAdapter<String> aa=new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,opciones);
        operaciones.setAdapter(aa);
        calculo();
    }
 
 
 
 
 
    public void calculo()
    { operaciones.setOnItemClickListener(new AdapterView.OnItemClickListener()
    { @Override
    public void onItemClick(AdapterView av, View v, int p, long id)
    { try
    { int valor1=Integer.parseInt(numero1.getText().toString());
        int valor2=Integer.parseInt(numero2.getText().toString());
        int total=0;
        switch(p)
        { case 0: total=valor1+valor2;
            resum.setText(""+total);
            break;
            case 1: total=valor1-valor2;
                reres.setText(""+total);
                break;
            case 2: total=valor1*valor2;
                remul.setText(""+total);
                break;
            case 3: total=valor1/valor2;
                rediv.setText(""+total);
                break;
        }
    }
    catch(NumberFormatException e)
    { textito.setText("faltan números");
    }
 
    }
    });
    }
 
 
}
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