如何在Android中单击textview [英] how to click on textview in android
问题描述
单击文本视图不起作用
我的xml是
< TextViewandroid:id ="@ + id/button2"android:layout_width ="wrap_content"android:layout_height ="fill_parent"android:layout_marginLeft ="5dp"android:layout_weight ="3"android:gravity ="center"android:textColor ="@ color/white"android:text =点击下载sevenstepstocollege"android:textSize ="15dp"android:onClick ="downloadLink"android:clickable ="true"></TextView>
我的活动代码是
公共无效下载链接(查看v){//字符串requestId = PurchasingManager.initiatePurchaseRequest(skuKye);//String requestId = PurchasingManager.initiateItemDataRequest("DeveloperSKU-1234");skuSet.add(skuKye);最终的字符串requestId = PurchasingManager.initiateItemDataRequest(skuSet);}
但是它不起作用.我无法单击该链接.请指导我
好,我使用以下代码使TextView可点击.
首先,将其添加到您的activity.xml中,以使TextView易于使用:
< TextViewandroid:id = android:id ="@ + id/button2"<!-id来获取此TextView->(...)android:onClick ="onClick"<!-添加功能onClick()->android:clickable ="true"<!-将布尔型clickable设置为true->/>
然后,在MainActivity.java中,添加:
private TextView textview;@Override受保护的void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//通过id获取TextViewtextview =(TextView)findViewById(R.id.button2);textview.setOnClickListener(new View.OnClickListener(){@Overridepublic void onClick(View v){//点击链接时的待办事项(TextView)}});}
正如我现在所看到的那样,您正在尝试使TextView中的链接可单击,而不仅仅是能够单击TextView.我将让下面的链接指向在Stack Overflow中解决的类似问题,您可能会发现有帮助./p>
android开发人员对TextView的引用:
https://developer.android.com/reference/android/widget/TextView.html
Stack Overflow中有关如何在可点击的链接中建立链接的类似问题可能会有所帮助:
如何使TextView中的链接可点击?a>
Click on text view is not working
My xml is
<TextView
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="3"
android:gravity="center"
android:textColor="@color/white"
android:text="click to download sevenstepstocollege"
android:textSize="15dp"
android:onClick="downloadLink"
android:clickable="true">
</TextView>
and My Activity code is
public void downloadLink(View v)
{
//String requestId = PurchasingManager.initiatePurchaseRequest(skuKye);
//String requestId=PurchasingManager.initiateItemDataRequest("DeveloperSKU-1234");
skuSet.add(skuKye);
final String requestId = PurchasingManager.initiateItemDataRequest(skuSet);
}
But it is not working.I am not able to click that link.please guide me
Well, I use the following code to make a TextView clickable.
First, add this at your activity.xml, to make TextView clikable:
<TextView android:id=android:id="@+id/button2" <!-- id to get this TextView --> (...) android:onClick="onClick" <!-- Add the function onClick() --> android:clickable="true" <!-- Set the boolean clickable to true --> />
Then, at your MainActivity.java, you add:
private TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the TextView by id
textview = (TextView) findViewById(R.id.button2);
textview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO when clicked on your link(TextView)
}
});
}
As I see now that you are trying to make a link from the TextView clickable, not just be able to click on the TextView I will let a link below to a similar question solved in Stack Overflow that you might find helpful.
The android developer reference to TextView:
https://developer.android.com/reference/android/widget/TextView.html
The similar question in Stack Overflow about how to make a links in a clickable that might be helpful:
How do I make links in a TextView clickable?
这篇关于如何在Android中单击textview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!