Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
刷屏时android listview背景未更改_Android_Listview_Android Listview_Swipe_Android Background - Fatal编程技术网

刷屏时android listview背景未更改

刷屏时android listview背景未更改,android,listview,android-listview,swipe,android-background,Android,Listview,Android Listview,Swipe,Android Background,我已使用设置了滑动列表视图。它确实提供了各种事件侦听器来处理与刷卡相关的事件 除了一件事,一切都很好 我只想更改刷过的列表项的背景色。一旦恢复,它就会恢复 我可以使用适配器中的点击事件来执行此操作。我本可以使用列表适配器来实现这一点,但由于我只想在向左滑动(侦听器)时更改背景,所以无法使用适配器。所以从适配器执行此操作可能不起作用 以下听众为我工作- swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {

我已使用设置了滑动列表视图。它确实提供了各种事件侦听器来处理与刷卡相关的事件

除了一件事,一切都很好

我只想更改刷过的列表项的背景色。一旦恢复,它就会恢复

我可以使用适配器中的点击事件来执行此操作。我本可以使用列表适配器来实现这一点,但由于我只想在向左滑动(侦听器)时更改背景,所以无法使用适配器。所以从适配器执行此操作可能不起作用

以下听众为我工作-

swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
    @Override
    public void onOpened(int position, boolean toRight) {       
         View v = swipeListView.getChildAt(position);
         swipeListView.getChildAt(position).setBackgroundColor(Color.CYAN);

         ci = u_items.get(position); // getter of list item data

         Toast.makeText(getApplicationContext(), ci.getTitle().toString(), Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onClosed(int position, boolean fromRight) {
    }

    @Override
    public void onListChanged() {
    }

    . // other listeners
    .
    .
    .
    .
    .
这不会引发任何错误或警告,但我看不到背景正在更改。Toast确实出现了,所以“向左滑动”侦听器实际上可以工作

也许,我在设置背景时做了些错事。不知道是什么。因为swipelistview是扩展ListView的自定义视图,我无法想象如何仅从该侦听器执行此操作

甚至,我也可以使用android列表选择来设置XML文件中的背景颜色,但它只适用于tap listener。所以这个选项也被取消了。除此之外,其他一切都非常完美


往正确的方向推一推就好了。如果需要进一步分析任何代码,我可以编辑问题。

您已经定义了v,这样您可以更好、更方便地使用它

View v = swipeListView.getChildAt(position);
v.setBackgroundColor(Color.CYAN);

您已经定义了v,因此可以更好、更容易地使用它

View v = swipeListView.getChildAt(position);
v.setBackgroundColor(Color.CYAN);

我可以通过获取背景视图并以这种方式进行更改来实现这一点。我使用onStartOpen方法而不是onOpen方法

@Override
public void onStartOpen(int position, int action, boolean right) {
    View v = mSwipeListView.getChildAt(position);
        if (v == null) return;

        if (right) { // nothing

        } else {
            final ImageView mCurrImage = (ImageView) v.findViewById(R.id.myImageView);
            mCurrShareImage.setBackground(Color.CYAN);
        }
    }
}

我可以通过获取背景视图并以这种方式进行更改来实现这一点。我使用onStartOpen方法而不是onOpen方法

@Override
public void onStartOpen(int position, int action, boolean right) {
    View v = mSwipeListView.getChildAt(position);
        if (v == null) return;

        if (right) { // nothing

        } else {
            final ImageView mCurrImage = (ImageView) v.findViewById(R.id.myImageView);
            mCurrShareImage.setBackground(Color.CYAN);
        }
    }
}

对我本来打算删除这个
视图v…
,因为它是不必要的。但这也不行。请尝试为此替换swipeListView。。这个是.getchildxxxys。我本来打算删除这个
视图v…
,因为它是不必要的。但这也不行。请尝试为此替换swipeListView。。this.getchildxxxI还尝试设置在此链接上找到的代码,但不知道从何处处理我也尝试设置在此链接上找到的代码,但不知道从何处处理此方法必须在何处实现?onStartOpen是BaseSwipeListViewListener中的一个方法。在我的例子中,它是在我使用SwipeListView的片段中实现的。mSwipeListView.setSwipeListViewListener(新的BaseSwipeListViewListener(){…@Override public void onStartOpen(int-position,int-action,boolean-right){必须在何处实现此方法?onStartOpen是BaseSwipeListViewListener中的一个方法。在我的例子中,它是在使用SwipeListView.mSwipeListView.setSwipeListViewListener的片段中实现的(新BaseSwipeListViewListener(){…@重写公共void onStartOpen(int位置,int操作,布尔右){