1

I have set listener for the TextView but it is not working.I want to start activity on click of text.I have placed my code can anyone suggest me any changes.

// This is my code

public void onClick(View v) {
        // TODO Auto-generated method stub

        int i = v.getId();
    //String roomName = textView[i].getText().toString();
    //Intent intentDeviceOperation = new Intent(v.getContext),DeviceOperation.class);
    //startActivity(intentDeviceOperation);

    //Intent i1 = new Intent(v.RoomForSpecificUser.this,DeviceOperation.class);
    //RoomForSpecificUser.this.startActivityForResult(i1,7);
    Intent ii = new Intent();
    ii.setClass(RoomForSpecificUser.this, DeviceOperation.class);

    }

It is not starting another activity and even not getting any error also.

Dhaivat Pandya
  • 6,499
  • 4
  • 29
  • 43
Akshay
  • 2,506
  • 4
  • 34
  • 55

4 Answers4

6

Do it this way and things will work

TextView tv = (TextView) findViewById(R.id.textView);
tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent ii = new Intent();
                ii.setClass(RoomForSpecificUser.this, DeviceOperation.class);

                            startActivity(ii);

            }
        });
Sarmad
  • 389
  • 2
  • 8
  • I have already used it for starting another intent but it is not showing any content in my xml file.Another thing i am getting text from database so i can't use the method findViewById(). – Akshay Jul 12 '11 at 07:05
0
              " Simply used Button Listener As TextView or EditText Listener  "

TextView tv = (TextView) findViewById(R.id.textView);

tv.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

                                               //Action performed

                                }

                    });
0

You haven't start the activity yet :)

Intent ii = new Intent();
ii.setClass(RoomForSpecificUser.this, DeviceOperation.class);
startActivity(ii);
Walid Hossain
  • 2,724
  • 2
  • 28
  • 39
  • 1
    Thanks Nik,but i thought It was the answer – Walid Hossain Jul 12 '11 at 06:37
  • @Walid Hossain I have already used it for starting another intent but it is not showing any content in my xml file.Another thing i am getting text from database so i can't use the method findViewById(). – Akshay Jul 12 '11 at 07:25
0
    class RoomForSpecificUser extends Service implements OnClickListener{
    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.textView);

    tv.setOnclickListener(this);


        }
    public void onClick(View v) { // TODO Auto-generated method stub

        int i = v.getId();
    //String roomName = textView[i].getText().toString();
    //Intent intentDeviceOperation = new Intent(v.getContext),DeviceOperation.class);
    //startActivity(intentDeviceOperation);

    //Intent i1 = new Intent(v.RoomForSpecificUser.this,DeviceOperation.class);
    //RoomForSpecificUser.this.startActivityForResult(i1,7);
    Intent ii = new Intent();
    ii.setClass(RoomForSpecificUser.this, DeviceOperation.class);

    }


    }
Rasel
  • 15,499
  • 6
  • 40
  • 50