is it possible in android to make text view clickable if yes then how ??and if not then what will be the way for make a label clickable??i want to implement a call activit
More easier directly in the XML : with clickable = true
<TextView
android:id="@+id/forgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="@string/forgotPassword"
android:onClick="forgotPassword"
android:clickable="true"
/>
We can also get click event on TextView
same as Button
& ImageView
.
and method is also same for all View.
like as
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
In the xml for that TextView include the field
android:onClick="functionName"
Then in your java file associated with that xml include this function
public void functionName(View view){
// do your stuff
}
Honestly, I found a flat button to work better for what I was doing with a RecyclerView:
<Button
android:id="@+id/btnFoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/borderlessButtonStyle"/>
Source: https://stackoverflow.com/a/30884132/2328637
Then customizing the button to fit my layout and finally adding the following to my MainActivity.java under onCreate
:
Button btnFoo = (Button) findViewById(R.id.btnFoo);
btnFoo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, FooActivity.class);
startActivity(intent);
}
});
Try this:
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});