Tôi đã có LinearLayout tùy chỉnh với con TextView nhỏ hơn. Tôi muốn có thể nhấp vào khu vực không được bao phủ bởi TextView, vì vậy tôi đặt clickable = true và onclicklistener thành LinearLayout, nhưng onClick không được kích hoạt. Nếu tôi đặt trình nghe onclick trên TextView, nó hoạt động như mong đợi ...onClick không được kích hoạt trên LinearLayout với con
Bất kỳ ai cũng có thể trợ giúp?
ar_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ar_item" android:layout_width="202dp"
android:layout_height="62dp" android:background="@drawable/bg_item_ar"
android:clickable="true">
<TextView android:id="@+id/ar_item_txt"
android:layout_width="164dp" android:layout_height="fill_parent"
android:paddingBottom="8dp" android:paddingLeft="8dp"
android:paddingTop="8dp" android:paddingRight="6dp" android:gravity="center"
android:background="#50000000" />
</LinearLayout>
tùy chỉnh của tôi LinearLayout
public class ARView extends LinearLayout
{
public ARView(final Context context, String name, String id)
{
super(context);
getLayoutInflater().inflate(R.layout.ar_item, this ,true);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.ar_item, null);
TextView textView = (TextView) findViewById(R.id.ar_item_txt);
textView.setText(name);
setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast t = Toast.makeText(context, "hey!", Toast.LENGTH_SHORT);
t.show();
}
});
}
}
tôi đang gặp vấn đề chính xác cùng, bạn đã tìm thấy một giải pháp? – longhairedsi