我有xml
handle onclick
xml
onClick of Button
工作onClick TextView
但row_listview.xml
不起作用。
我的<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#ffffff"
android:gravity="center"
android:orientation="horizontal" >
<HorizontalScrollView
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/row_cell_text_dummy_multilevel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:singleLine="false"
android:textColor="#ffffff"
android:textSize="10dp" />
<Button
android:id="@+id/row_cell_btn_multilevel"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:onClick="CellButtonClick" />
<TextView
android:id="@+id/row_cell_text_multilevel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="7dp"
android:layout_weight="1"
android:gravity="center|left"
android:clickable="true"
android:onClick="CellTextClick"
android:singleLine="true"
android:textColor="#000000"
android:textSize="10dp" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
:
StartActivity.class
而贝娄是我的public class StartActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
}
public void CellTextClick(View v){
try {
Log.i("test", "OK");
} catch (Exception e) {
}
}
}
:
android:onClick="CellButtonClick"
注意:我的android:onClick="CellTextClick"
工作正常,但我的{{1}}无效。
答案 0 :(得分:2)
尝试TextView
android:clickable="true"
答案 1 :(得分:1)
我猜你有一个adapter
,如果你有adapter
,onclickListener
TextView
,android:id="@+id/row_cell_text_multilevel"
您应该对其进行评论,然后使用android:onClick="CellButtonClick"
。
答案 2 :(得分:0)
将此添加到textview android:clickable =&#34; true&#34;
答案 3 :(得分:0)
您是否尝试在TextView下设置android:clickable = "true"
?
答案 4 :(得分:0)
在xml中添加此代码
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
以下是java代码
public class test extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
TextView tv= (TextView)findViewById(R.id.textView1);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(test.this, "Textview Clicked", Toast.LENGTH_LONG).show();
}
});
}
}
工作