2014-10-08 80 views
0

我有一个类扩展了ListActivity。里面有3个按钮和一个列表视图(可点击的项目),列表项和2个按钮工作正常,但没有响应点击(其创建方式与其他方式完全相同)。我认为这是与按钮的可聚焦性相关的东西,我已经尝试过android:focusable =“true”和“false”,但没有任何变化。1个listview和3个按钮。 1按钮不可点击,为什么?

这是我的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

在所有按钮中添加android:clickable =“true”android:focusable =“false”请尝试这个 – 2014-10-08 14:00:44

+0

并请告诉我发生了什么事情它已经起作用 – 2014-10-08 14:01:24

+1

我不是e onClick =“...”任何地方。你如何指定被调用的内容?你是否为最后一个按钮指定了它? – 18446744073709551615 2014-10-08 14:01:30

回答

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(); 
     } 
    }); 
} 

尝试“干净”和“重建”的项目或发布您的代码在这里

+0

你说得对,问题出在onclicklistener里面。谢谢! – MauriF 2014-10-08 14:26:09