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.

4 Answers 4

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);

            }
        });
1
  • 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, 2011 at 7:05
0

You haven't start the activity yet :)

Intent ii = new Intent();
ii.setClass(RoomForSpecificUser.this, DeviceOperation.class);
startActivity(ii);
2
  • 1
    Thanks Nik,but i thought It was the answer Jul 12, 2011 at 6: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, 2011 at 7: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);

    }


    }
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

                                }

                    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.