How to make TextView clickable, Android?
I am very new to Android and I have some doubts.
I have TextView
:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go Back" />
How can I make the text Go Back
look like clickable? I am asking in terms of appearance. TextView
should appear as interactive as Button
received.
Thanks in advance.
source to share
create xml file in your folder named "mybutton.xml" and write this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_pressed="true"
android:drawable="@drawable/mybutton2"/>
<item
android:drawable="@drawable/mybutton1"/>
</selector>
Then add two pngs to your hyphenation folder ... mybutton1.png, mybutton2.png. This way you have 2 different states for your button.
Now set the background to the text box:
android:background="@drawable/mybutton"
then in your code you have to set clicklistener:
findViewById(R.id.mytextview).setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//your code goes here
}
});
And that's all ... You can use shapes instead of images.
source to share
Try the following:
final TextView view = (TextView) findViewById(R.id.textview1);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// request your webservice here. Possible use of AsyncTask and ProgressDialog
// show the result here - dialog or Toast
}
};);
source to share
You don't even need a listener:
<TextView
android:id="@+id/needCheeseburger"
android:clickable="true"
android:onClick="getCheeseburger" />
And then just:
public void getCheeseburger(View view) {
Intent intent = new Intent(this, giveMeCheeseburger.class);
startActivity(intent);
}
This works great for me.
source to share
use android:clickable="true"
TextView
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="Large Text" />
text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
source to share
Hopefully everything will be used for u: -
boolean text_click =false;
TextView textview = (TextView) findViewById(R.id.textview1);
public OnClickListener textOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
if (Constants.text_click) {
textview.setBackgroundResource(R.drawable.textbox);
text_click = false;
} else {
textview.setBackgroundResource(R.drawable.textboxonpress);
text_click = true;
}
}
};
source to share