Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making a textview clickable in android

Tags:

android

I am making an android application,I have 4 textviews namely ProductId,Title,description,image.I want when i click on each one of them product id should be displayed.I have a webservice for this.

Output of webservice is

vmsc>
<response code="0" message="Success"/>
−
<responsedata>
−
<productcategories>
−
<productcategory>
<id>1</id>
<title>Celebrities</title>
<description>Celebrities</description>
<image>
        </image>
</productcategory>
−
<productcategory>
<id>2</id>
<title>Music</title>
<description>Music</description>
<image>
        </image>
</productcategory>
−
<productcategory>
<id>3</id>
<title>Sports</title>
<description>Sports</description>
<image>
        </image>
</productcategory>
−
<productcategory>
<id>4</id>
<title>Fashion</title>
<description>Fashion</description>
<image>
        </image>
</productcategory>
−
<productcategory>
<id>5</id>
<title>Religion</title>
<description>Religion</description>
<image>
        </image>
</productcategory>
−
<productcategory>
<id>6</id>
<title>Others</title>
<description>Others</description>
<image>
        </image>
</productcategory>
</productcategories>
</responsedata>
</vmsc>

Thanks in advance Tushar

like image 762
User Avatar asked Apr 04 '11 10:04

User


People also ask

Can you make a TextView clickable?

In Android, the most common way to show a text is by TextView element. The whole text in the TextView is easy to make clickable implementing the onClick attribute or by setting an onClickListener to the TextView.

Can TextView be clickable in android?

Just like Buttons and ImageViews we can add onClickListeners to TextViews by simply adding the attribute android:onClick="myMethod" to your TextView XML tag. The other way, TextView tv = (TextView) this.


1 Answers

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
  }

});
like image 151
Vladimir Ivanov Avatar answered Sep 27 '22 18:09

Vladimir Ivanov