Pass from an array a text to another activity and this is clickable

0

I have a two-dimensional array that goes to another activity with an adapter. In the observations section I want to pass a text that when pressed activates an intent or similar to launch another activity. I do not know if I explain myself, I would like to pass "Citizen Security Law" and when clicking on the text go to another activity or a url. Thanks for your time.

I pass the classes to you.

Main class

public class seguridad_ciudana extends AppCompatActivity implements Filter.FilterListener {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate ( savedInstanceState );
    setContentView ( R.layout.seguridad_ciudana );

    final String [][] datos = {

            {"1","1,2","-","-","1. La seguridad ciudadana es un requisito indispensable para el pleno ejercicio de los derechos fundamentales y las libertades públicas, y su salvaguarda, como bien jurídico de carácter colectivo, es función del Estado, con sujeción a la Constitución y a las Leyes.\n\n2. Esta Ley tiene por objeto la regulación de un conjunto plural y diversificado de actuaciones de distinta naturaleza orientadas a la tutela de la seguridad ciudadana, mediante la protección de personas y bienes y el mantenimiento de la tranquilidad de los ciudadanos.\n",""},


    };

    lvElements = (ListView) findViewById(R.id.lvElements);
    tvTotals = (TextView) findViewById(R.id.tvTotals);
    etSearch = (EditText) findViewById(R.id.etSearch);
    etSearch.setFilters(new InputFilter[] {new InputFilter.AllCaps()});

    List data = new ArrayList ();
    data.addAll(Arrays.asList ( getResources ().getStringArray ( R.array.seguridadCiudadanaLista ) ));


    adapter = new StringFilterCountArrayAdapter(this,R.layout.item_list_trafico, R.id.codigo_token,data );

    lvElements.setAdapter(adapter);
    onFilterComplete(data.size());


    // Evento para cuando doy click en algun elemento de la lista ( ListView )
    lvElements.setOnItemClickListener ( new AdapterView.OnItemClickListener () {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String Seleccion= parent.getItemAtPosition(position).toString();
            if (Seleccion.equalsIgnoreCase("Objeto"))           {
                String Seleccion_Mesoamerica = (String)lvElements.getItemAtPosition(position);
                Intent visorDetalles = new Intent ( view.getContext (), detalles_segudirad_ciudadana.class );
                visorDetalles.putExtra ( "ARTICULO", datos[0][0] );
                visorDetalles.putExtra ( "APARTADO", datos[0][1] );
                visorDetalles.putExtra ( "CALIFICACION", datos[0][2] );
                visorDetalles.putExtra ( "CUANTIA", datos[0][3] );
                visorDetalles.putExtra ( "DESCRIPCION", datos[0][4] );
                visorDetalles.putExtra ( "OBSERVACIONES", datos[0][5] );
                startActivity ( visorDetalles );      }


        }
    });


} // Fin método onCreate

}

Class details

public class detalles_segudirad_ciudadana extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate ( savedInstanceState );
    setContentView ( R.layout.detalles_segudirad_ciudadana );

    TextView articulo = (TextView)findViewById ( R.id.tvarticuloD );
    TextView apartado = (TextView)findViewById ( R.id.tvapartadoD );
    TextView observaciones = (TextView)findViewById ( R.id.tvopcionD );
    TextView calificacion = (TextView)findViewById ( R.id.tvcalificacionD );
    TextView descripcion = (TextView)findViewById ( R.id.tvdescripcionD );
    TextView cuantia = (TextView)findViewById ( R.id.tvcuantiaD );

    Intent intent = getIntent ();
    Bundle b = intent.getExtras ();

    if (b!=null) {
        articulo.setText ( (b.getString ( "ARTICULO" )) );
        apartado.setText ( (b.getString ( "APARTADO" )) );
        observaciones.setText ( (b.getString ( "OBSERVACIONES" )) );
        calificacion.setText ( (b.getString ( "CALIFICACION" )) );
        cuantia.setText ( (b.getString ( "CUANTIA" )) );
        descripcion.setText ( (b.getString ( "DESCRIPCION" )) );

    }
}
    
asked by Ruben Gallegos 04.11.2018 в 12:38
source

1 answer

0

You declare a String before onCreate:

 String valor = "";

You assign the value in the Bundle:

 valor = b.getString ("OBSERVACIONES");

You assign the onClick to the view, and with if / else you compare the String obtained to assign the intents:

 observaciones.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if("Ley Seguridad Ciudadana".equals(valor)) {
            Intent intent = new Intent(getApplicationContext(),LeyseguridadActivity.class);
            startActivity(intent);        
            }else if("Codigo Penal".equals(valor)) {
                Intent intent = new Intent(getApplicationContext(),CodigopenalActivity.class);
                startActivity(intent); 
            }else if(...)) {
                Intent ...
            }
        }
    });
    
answered by 05.11.2018 / 22:35
source