我正在制作一个Android应用程序,我有4个文本视图,即ProductId,标题,描述,图像.我希望当我点击它们中的每一个时,应该显示产品ID.我有一个web服务.
webservice的输出是
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>
Run Code Online (Sandbox Code Playgroud)
在此先感谢Tushar
Vla*_*nov 18
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
}
});
Run Code Online (Sandbox Code Playgroud)
你也可以使用像xml这样做
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="handleOnClick"
android:clickable="true"
android:text="Clickable TextView"
android:textSize="30sp" />
Run Code Online (Sandbox Code Playgroud)
并处理onClick喜欢
public void handleOnClick(View view)
{
switch(view.getId())
{
case R.id.textView:
//do your stufff here..
break;
default:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30138 次 |
| 最近记录: |