Android listview 在ListView、自定义适配器中仅启用1个按钮

Android listview 在ListView、自定义适配器中仅启用1个按钮,android-listview,custom-adapter,Android Listview,Custom Adapter,我遇到一个问题,需要在ListView中启用我的按钮。奇怪的是: public class CookingStepAdapter extends ArrayAdapter<CookingStep> { ... private void addButtonToList(Button clock, Button skip){ if (list_clock_button == null) { list_clock_b

我遇到一个问题,需要在ListView中启用我的按钮。奇怪的是:

 public class CookingStepAdapter extends ArrayAdapter<CookingStep> {

...
       private void addButtonToList(Button clock, Button skip){
            if (list_clock_button == null) {
                list_clock_button = new ArrayList<Button>();
                iterate = 0;
            }
            if (list_skip_button == null)
                list_skip_button = new ArrayList<Button>();
            list_clock_button.add(clock);
            list_skip_button.add(skip);

            clock.setEnabled(true);
            skip.setEnabled(true);

            list_clock_button.get(0).setEnabled(true);
            list_clock_button.get(0).setFocusable(true);
            list_clock_button.get(0).setFocusableInTouchMode(true);
            list_clock_button.get(0).invalidate();

            list_skip_button.get(0).setEnabled(true);
            list_skip_button.get(0).setFocusable(true);
            list_skip_button.get(0).setFocusableInTouchMode(true);
            list_skip_button.get(0).postInvalidate();
        }
}

所有按钮都被启用的原因是您正在设置所有按钮,以便自己启用。要设置任何特定按钮启用,您必须检查id或项目位置以将该特定按钮设置为启用。 例如:-

if(clock.getID == R.id.some_id_in_xml){
    clock.setEnabled(true);
}

但在此之前,您必须检查项目的位置,以在列表中选择所需的项目。

但我确实将它们保存到了列表中,并且此列表中的引用与按钮的引用匹配。以及
final Button Button=(Button)rowView.findViewById(R.id.Button\u timer)获取的(按钮时钟,按钮跳过)并且,如果您所说的是问题所在,那么第一个选项也不应该起作用。您可以提供适配器的getView()函数的代码吗?我已将我的getView添加到问题中,您不必在列表中添加按钮,只需将它们设置为启用或禁用即可。只需在
CookingStep
类中添加两个数据成员,如IsButtoneTable和IsSkipButtoneTable,并根据需要设置这些值,然后根据这些标志设置按钮属性。因为
ListView
在滚动时总是刷新其视图,并且必须根据数据的arraylist重置所有属性。在您的例子中,
CookingStep
。即使ListView重置了所有属性,这也很奇怪,因为我将该列表设置为静态。你的意思是我不能操作适配器内的数据?因为我甚至不知道我应该在哪里做这件事,如果不是在适配器内部的话,因为这是我设置按钮侦听器的唯一方法。列表中有很多项,在这些项之间,有按钮的项和没有按钮的项,所以我希望在开始时只启用一个按钮,然后当用户按下它时,它将被禁用,下一个按钮将被启用。
if(clock.getID == R.id.some_id_in_xml){
    clock.setEnabled(true);
}