How to call a class from an event?

1

I have a main class, through her call a layout with listview , depending on the click opens a different screen with different customer data.

The following piece of code:

public OnItemClickListener chamaAtividades(){
    return(new OnItemClickListener(){
        @Override

        public void onItemClick(AdapterView<?> av, View v, int position, long id) {

            Intent intent;

            switch(position){
                case 0:

                        setContentView(R.layout.atividade1);

                        TextView b = (TextView) findViewById(R.id.barra);
                        b.setText(new String("Gastronomia"));

                        ImageView iv = (ImageView) findViewById(R.id.iv);
                        iv.setImageResource(R.drawable.acai3);

                        TextView t1 = (TextView) findViewById(R.id.t1);
                        t1.setText(new String("Açaí da Praça"));

                        TextView t2 = (TextView) findViewById(R.id.t2);
                        t2.setText(new String("Texto descritivo do acai !"));
                        Linkify.addLinks(t2, Linkify.ALL);

                        TextView t3 = (TextView) findViewById(R.id.t3);
                        t3.setText(new String("(035)3341-6969"));
                        Linkify.addLinks(t3, Linkify.ALL);

                        TextView t4 = (TextView) findViewById(R.id.t4);
                        t4.setText(new String("www.acaidapraca.com"));
                        Linkify.addLinks(t4, Linkify.ALL);

                        TextView t5 = (TextView) findViewById(R.id.t5);
                        t5.setText(new String("[email protected]"));
                        Linkify.addLinks(t5, Linkify.ALL);

                        TextView t6 = (TextView) findViewById(R.id.t6);
                        t6.setText(new String("facebook.com/acaidapraca"));
                        Linkify.addLinks(t6, Linkify.ALL);

                           ...

In this example clicking the first ( case 0 ) will call the layout atividade1 and set the texts and images above.

Within atividade1.xml has a button and wanted to give an action to the button to call another class. How to do this?

I was trying at the end of this code to implement something like this:

                        ...

                        TextView t6 = (TextView) findViewById(R.id.t6);
                        t6.setText(new String("facebook.com/acaidaporra"));
                        Linkify.addLinks(t6, Linkify.ALL);


                            Button botao = (Button) findViewById(R.id.voltar);
                            botao.setOnClickListener(new View.OnClickListener() {
                            new Mapa().setVisible(true);

                        ...

But it did not work.

    
asked by anonymous 18.11.2014 / 03:04

1 answer

2
___ erkimt ___ How to call a class from an event? ______ qstntxt ___

I have a main class, through her call a layout with Intent , depending on the click opens a different screen with different customer data.

The following piece of code:

Button botao = (Button) findViewById(R.id.voltar);
botao.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

        //Criação do Intent
        Intent intent = new Intent(AtividadeAtual.this, NovaAtividadeASerChamada.class);

        //Adição de informação extra se pretender passar informação
        intent.putExtra("variavel", valorDaVariavel);

        //Cria a nova actividade
        startActivity(intent);
    }
});

In this example clicking the first ( %code% ) will call the layout %code% and set the texts and images above.

Within %code% has a button and wanted to give an action to the button to call another class. How to do this?

I was trying at the end of this code to implement something like this:

Button botao = (Button) findViewById(R.id.voltar);
botao.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

        //Criação do Intent
        Intent intent = new Intent(AtividadeAtual.this, NovaAtividadeASerChamada.class);

        //Adição de informação extra se pretender passar informação
        intent.putExtra("variavel", valorDaVariavel);

        //Cria a nova actividade
        startActivity(intent);
    }
});

But it did not work.

    
______ ___ azszpr40860

To start a new Activity you just have to create a %code% and invoke the new Activity :

%pre%     
___
18.11.2014 / 11:00