当前位置: 代码迷 >> Android >> android-文本点击的两种步骤(十)
  详细解决方案

android-文本点击的两种步骤(十)

热度:88   发布时间:2016-04-28 01:54:19.0
android--文本点击的两种方法(十)
1.第一种如下:
	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.activity_main);				Log.d("debug","textview onCreate");		textview = (TextView)this.findViewById(R.id.textview);		textview.setClickable(true);		textview.setFocusable(true);		    	textview.setOnClickListener(new OnClickListener(){			@Override			public void onClick(View v){				Log.d("debug","textview click start");			}		});			}

需要设置两个属性:

textview.setClickable(true);textview.setFocusable(true);

2.第二种

1)需要设置一下android:onClick="onClick_Event"

   <TextView        android:id="@+id/textview"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world"         android:onClick="onClick_Event"/>

2)代码里面实现:

	public void onClick_Event(View v){		Log.d("debug","textview click start");	}


  相关解决方案