TextView textView = findViewById(R.id.my_text_view); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Implement your logic here } });
TextView textView = findViewById(R.id.my_text_view); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, NewActivity.class); startActivity(intent); } });In this example, we create a TextView object and register a new OnClickListener using the setOnClickListener method. The OnClickListener is defined as an anonymous inner class that implements the View.OnClickListener interface. The onClick method is then overridden with the implementation of code that creates a new Intent object to open a new activity, and then starts that activity using the startActivity method. This package library for these examples of the android.widget.TextView setOnClickListener is `android.widget`.