[英]How to make a TextView Clickable with a extra ID in android
I am developing a Android Application, where i have multiple textView and I want those textview clickable. 我正在开发一个Android应用程序,其中有多个textView,并且我希望这些textview可单击。 When I will click those textView I will get a common empty form but with a static ID in the top for every textview.
当我单击这些textView时,将得到一个常见的空表格,但每个textview的顶部都有一个静态ID。
For example: If I have 3 product name in 3 text view, if I click on textView1, a previously made layout will be shown and there will be a static ID with my product name in the top, then there will be form to filling up the details of the product.If I click on the textView2 then the form will be same only the Static ID and the product name will change. 例如:如果我在3个文本视图中有3个产品名称,如果单击textView1,将显示以前制作的布局,并且在顶部将有一个静态ID,其产品名称为我,然后将有填写表格产品的详细信息。如果我单击textView2,则表单将相同,仅静态ID和产品名称将更改。
I hope you guys understood what I wanted to explain. 我希望你们能理解我要解释的内容。
I am new in application development so I need some simple solution. 我是应用程序开发的新手,因此我需要一些简单的解决方案。 So far I have made a layout of my form and I have also made a clickable Layout.
到目前为止,我已经完成了表单的布局,并且还完成了可点击的布局。 So I need to know how I would make the class and function to call the layout and plus the static ID.
因此,我需要知道如何使类和函数调用布局以及静态ID。
Layout of the product name and the Clickable TextView: 产品名称和Clickable TextView的布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/p85"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="11dp"
android:textStyle="bold"
android:layout_marginTop="12dp"
android:text="@string/p85"
android:ems="7"
android:textSize="35sp"
android:textColor="#375C34"
android:clickable="true"
android:background="@drawable/product_list_view"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</ScrollView>
ProductList.java file that call the product_list.xml 调用product_list.xml的ProductList.java文件
import android.app.Activity;
import android.os.Bundle;
public class ProductList extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.product_list);
}
}
In xml in your textview put : android:onClick="onClick" 在XML中,将textview放在:android:onClick =“ onClick”
And have this 还有这个
public void onClick(View v) {
switch(v.getId()){
case R.id.TextViewFromXml):
// do something
break;
}
}
Or Remove this 或删除此
Textview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
First set Tag(ie your Static ID) to TextView and then set Clicklistner 首先将Tag(即您的静态ID)设置为TextView,然后设置Clicklistner
tv.setTag("1234");
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
myId=tv.getTag();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.