我有一个扩展ListActivity的类。里面有3个按钮和一个列表视图(可点击的项目),列表项和2个按钮工作正常但一个不响应点击(它的创建方式与其他按钮完全相同)。我认为它与按钮的可聚焦性有关,我已经尝试过android:focusable =" true"和"假"但没有任何改变。
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_below="@+id/checkall"
android:layout_width="match_parent"
android:layout_height="400dp" >
</ListView>
<Button
android:id="@+id/checkall"
android:layout_height="38dp"
android:layout_width="wrap_content"
android:layout_marginLeft="19dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:text="Seleccionar todos"
android:background="#D1D1D1" />
<Button
android:id="@+id/uncheckall"
android:layout_height="38dp"
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/checkall"
android:layout_alignParentTop="true"
android:text="Borrar selección"
android:background="#D1D1D1"
android:layout_alignParentRight="true" />
//this is the one not accepting clicks -->
<Button
android:id="@+id/mostrar"
android:layout_height="49dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:text="Mostrar en mapa"
android:background="#D1D1D1" />
</RelativeLayout>
答案 0 :(得分:2)
您的布局没有问题,它可以正常使用此代码隐藏:
public class MyActivity extends ListActivity {
Button checkall, uncheckall, mostrar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
checkall = (Button) findViewById(R.id.checkall);
uncheckall = (Button) findViewById(R.id.uncheckall);
mostrar = (Button) findViewById(R.id.mostrar);
checkall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MyActivity.this, "checkall is clicked", Toast.LENGTH_SHORT).show();
}
});
uncheckall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MyActivity.this, "uncheckall is clicked", Toast.LENGTH_SHORT).show();
}
});
mostrar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MyActivity.this, "mostrar is clicked", Toast.LENGTH_SHORT).show();
}
});
}
尽量清理&#39;和&#39;重建&#39;您的项目或在此处发布您的代码