我认为因为我的ListView
设置为layout_height="match_parent"
,所以Buttons
不会被称为onClick
方法。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView == null) {
Log.d(TAG_DEBUG,"0");
} else{
Button button1 = (Button) convertView.findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG_DEBUG, "TEST");
}
});
}
return super.getView(position, convertView, parent);
}
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/num_ord"
android:background="@drawable/fon_ord"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textColor="#FFFFFF"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/title_ord"
android:textColor="#000000"
android:typeface="serif"
android:textStyle="normal|italic"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Sum:"
android:id="@+id/textView2"
android:textColor="#FFFFFF"
android:background="@drawable/fon_ord"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/sum_ord"
android:layout_gravity="left|center_horizontal"
android:layout_marginTop="-24dp"
android:textColor="#000000"
android:layout_marginLeft="64dp"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Col:"
android:id="@+id/textView3"
android:textColor="#FFFFFF"
android:background="@drawable/fon_ord"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/count_ord"
android:layout_gravity="left|center_horizontal"
android:layout_marginTop="-24dp"
android:textColor="#000000"
android:layout_marginLeft="106dp"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DD:"
android:id="@+id/textView4"
android:textColor="#ffffff"
android:background="@drawable/fon_ord"
android:focusable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/date_ord"
android:layout_gravity="left|center_horizontal"
android:layout_marginTop="-24dp"
android:textColor="#000000"
android:layout_marginLeft="50dp"
android:focusable="false" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="127dp"
android:layout_height="36dp"
android:text="Del"
android:id="@+id/button1"
android:layout_marginTop="20dp"
android:focusable="false" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="127dp"
android:layout_height="36dp"
android:text="Ed"
android:id="@+id/button2"
android:layout_gravity="right"
android:layout_marginTop="-37dp"
android:layout_marginRight="4dp"
android:focusable="false" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list_orders"
android:focusable="true" />
</LinearLayout>
当我按下按钮时,没有任何反应,为什么?