根据自定义适配器中的条件更改特定行的背景

2024-04-29

我试图根据从远程服务器上的数据库收到的标志来更改行的背景颜色。

在我的代码中,我创建了一个名为“disable”的 ArrayList,其中包含所有已标记的位置。我想将禁用列表中的内容与我的 ListView 中的位置相匹配。 我研究了几篇帖子,但没有一个明确说明如何做到这一点。我将找到的内容拼凑起来,并将其放入下面的自定义适配器中。

据我了解, public int getItemViewType(intposition) 可以根据条件选择特定行并更改其属性。满足这个条件时如何更改背景?我的程序中 getItemViewType(intposition) 中的代码不起作用,但您可以看到我正在尝试执行的操作。

问题1:我需要制作两个xml布局文件吗?一个用于正常视图,另一个用于禁用视图? 问题 2:您知道有哪些我可以效仿的实现此目标的示例吗?

package com.convention.notification.app;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class NewsRowAdapter extends ArrayAdapter<Item> {

    private Activity activity;
    private List<Item> items;
    private Item objBean;
    private int row;
    private List<Integer> disable;
    View view ;


    public NewsRowAdapter(Activity act, int resource, List<Item> arrayList, List<Integer> disableList) {
        super(act, resource, arrayList);
        this.activity = act;
        this.row = resource;
        this.items = arrayList;
        this.disable=disableList;

        System.out.println("results of delete list a:"+disable.toString()); 


    }

    public int getCount(){
       return items.size();
     }

    public Item getItem(int position){
         return null;
       }

    public long getItemId(int position){
       return position;
    }

    @Override
    public int getViewTypeCount() {
        return 2;


      }

   @Override
    public int getItemViewType(int position) {

        for (int s: disable){


           if (s == position){

            //   view.setBackgroundColor(Color.YELLOW);

           }


        }
        return position;

    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
         view = convertView;


        ViewHolder holder;
        if (view == null) {
            //ViewHolder is a custom class that gets TextViews by name
            holder = new ViewHolder();

            LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(row, null);


            // holder.txtViewDescription = (TextView) convertView.findViewById(R.id.txtViewDescription); 


            /* setTag Sets the tag associated with this view. A tag can be used to
             * mark a view in its hierarchy and does not have to be unique 
             * within the hierarchy. Tags can also be used to store data within
             * a view without resorting to another data structure.

*/
        view.setTag(holder);
        } else {



            //the Object stored in this view as a tag
            holder = (ViewHolder) view.getTag();
        }

        if ((items == null) || ((position + 1) > items.size())){

            return view;
        }

        objBean = items.get(position);


        holder.tv_event_name = (TextView) view.findViewById(R.id.tv_event_name);
        holder.tv_event_date = (TextView) view.findViewById(R.id.tv_event_date);
        holder.tv_event_start = (TextView) view.findViewById(R.id.tv_event_start);
        holder.tv_event_end = (TextView) view.findViewById(R.id.tv_event_end);
        holder.tv_event_location = (TextView) view.findViewById(R.id.tv_event_location);


        if (holder.tv_event_name != null && null != objBean.getName()
                && objBean.getName().trim().length() > 0) {
            holder.tv_event_name.setText(Html.fromHtml(objBean.getName()));

        }
        if (holder.tv_event_date != null && null != objBean.getDate()
                && objBean.getDate().trim().length() > 0) {
            holder.tv_event_date.setText(Html.fromHtml(objBean.getDate()));
        }
        if (holder.tv_event_start != null && null != objBean.getStartTime()
                && objBean.getStartTime().trim().length() > 0) {
            holder.tv_event_start.setText(Html.fromHtml(objBean.getStartTime()));
        }
        if (holder.tv_event_end != null && null != objBean.getEndTime()
                && objBean.getEndTime().trim().length() > 0) {
            holder.tv_event_end.setText(Html.fromHtml(objBean.getEndTime()));
        }
        if (holder.tv_event_location != null && null != objBean.getLocation ()
                && objBean.getLocation ().trim().length() > 0) {
            holder.tv_event_location.setText(Html.fromHtml(objBean.getLocation ()));

        }


        return view;
    }

    public class ViewHolder {
        public TextView 
        tv_event_name,
        tv_event_date,
        tv_event_start,
        tv_event_end,
        tv_event_location
        /*tv_event_delete_flag*/;


    }


}

Logcat:

06-11 00:06:43.133: D/dalvikvm(60): GC_EXPLICIT freed 230K, 45% free 4939K/8839K, external 3511K/3903K, paused 81ms
06-11 00:06:43.133: I/installd(34): unlink /data/dalvik-cache/data@[email protected] /cdn-cgi/l/email-protection@classes.dex
06-11 00:06:43.133: D/AndroidRuntime(528): Shutting down VM
06-11 00:06:43.173: D/dalvikvm(528): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 1ms+0ms
06-11 00:06:43.173: D/jdwp(528): Got wake-up signal, bailing out of select
06-11 00:06:43.173: D/dalvikvm(528): Debugger has detached; object registry had 1 entries
06-11 00:06:43.203: I/dalvikvm(528): JNI: AttachCurrentThread (from ???.???)
06-11 00:06:43.203: I/AndroidRuntime(528): NOTE: attach of thread 'Binder Thread #3' failed
06-11 00:06:43.653: D/AndroidRuntime(542): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
06-11 00:06:43.653: D/AndroidRuntime(542): CheckJNI is ON
06-11 00:06:44.223: D/AndroidRuntime(542): Calling main entry com.android.commands.am.Am
06-11 00:06:44.243: I/ActivityManager(60): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.convention.notification.app/.DataView } from pid 542
06-11 00:06:44.273: I/ActivityManager(60): Start proc com.convention.notification.app for activity com.convention.notification.app/.DataView: pid=550 uid=10042 gids={3003}
06-11 00:06:44.323: D/AndroidRuntime(542): Shutting down VM
06-11 00:06:44.323: D/dalvikvm(542): GC_CONCURRENT freed 103K, 69% free 319K/1024K, external 0K/0K, paused 1ms+1ms
06-11 00:06:44.334: D/dalvikvm(542): Debugger has detached; object registry had 1 entries
06-11 00:06:45.503: I/ActivityManager(60): Displayed com.convention.notification.app/.DataView: +1s233ms
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :1
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :6
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :14
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :15
06-11 00:06:47.163: I/System.out(550): item disalbed is at postion :18
06-11 00:06:47.163: I/System.out(550): results of delete list :[1, 6, 14, 15, 18]
06-11 00:06:47.163: I/System.out(550): results of delete list  in Adapeter:[1, 6, 14, 15, 18]
06-11 00:06:47.173: I/System.out(550):  set adapaer to list view called;
06-11 00:06:50.693: D/dalvikvm(237): GC_EXPLICIT freed 8K, 51% free 2725K/5511K, external 1625K/2137K, paused 61ms
06-11 00:06:55.783: D/dalvikvm(264): GC_EXPLICIT freed 17K, 52% free 2778K/5703K, external 1625K/2137K, paused 98ms
06-11 00:07:05.163: D/dalvikvm(308): GC_EXPLICIT freed 15K, 49% free 3363K/6535K, external 1625K/2137K, paused 43ms
06-11 00:07:10.284: D/dalvikvm(361): GC_EXPLICIT freed 15K, 48% free 3523K/6727K, external 1625K/2137K, paused 102ms
06-11 00:07:15.303: D/dalvikvm(378): GC_EXPLICIT freed 6K, 51% free 2718K/5511K, external 1625K/2137K, paused 73ms
06-11 00:07:20.383: D/dalvikvm(201): GC_EXPLICIT freed 21K, 50% free 2995K/5959K, external 1625K/2137K, paused 121ms
06-11 00:07:25.463: D/dalvikvm(130): GC_EXPLICIT freed 114K, 48% free 3089K/5895K, external 4932K/5608K, paused 124ms
06-11 00:11:22.113: D/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol

- - - - - - - - - - - - - 更新 - - - - - - - - - - - - ------ 我通过删除 getItem() 方法修复了此异常错误,并且我能够在列表中的一些视图上看到黄色背景。

当前的问题是在 while 循环中。我试图将我的列表视图与标记的项目进行比较,并且只在标记的项目上放置黄色背景。然而,每四个视图中我都会看到黄色背景。这不是我打算做的。您能否建议我如何修复 While 循环和/或 for 循环中的逻辑以使黄色背景与正确的位置/视图匹配?

这是更新后的代码:

package com.convention.notification.app;

import java.util.List;



import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class NewsRowAdapter extends ArrayAdapter<Item> {

    private Activity activity;
    private List<Item> items;
    private Item objBean;
    private int row;
    private List<Integer> disable;
    View view ;

    public NewsRowAdapter(Activity act, int resource, List<Item> arrayList, List<Integer> disableList) {
        super(act, resource, arrayList);
        this.activity = act;
        this.row = resource;
        this.items = arrayList;
        this.disable=disableList;

        System.out.println("results of delete list a:"+disable.toString()); 



    }






            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {
                View view = convertView;
                ViewHolder holder;
                if (view == null) {
                    LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    view = inflater.inflate(row, null);



                    try{
                                int j = 0;
                                while (j < items.size()) {
                                    for(int k =0;k< disable.size();k++){
                                        if(position == disable.get(k)){
                                            view.setBackgroundColor(Color.YELLOW);
                                            System.out.println("background set to yellow at disable "+disable.get(j));
System.out.println("background set to yellow at position "+position);
                                        } else {
                                            view.setBackgroundColor(Color.WHITE);
            System.out.println("background set to white at position "+position);

                    }
                                    }

                                    j++;   
                                }
                    }catch(IndexOutOfBoundsException e){

                    System.out.println(" crash");
                    }




                    //ViewHolder is a custom class that gets TextViews by name: tvName, tvCity, tvBDate, tvGender, tvAge;
                    holder = new ViewHolder();

                    /* setTag Sets the tag associated with this view. A tag can be used to
                     *  mark a view in its hierarchy and does not have to be unique 
                     *  within the hierarchy. Tags can also be used to store data within
                     *   a view without resorting to another data structure.

        */
                    view.setTag(holder);
                } else {

                    //the Object stored in this view as a tag
                    holder = (ViewHolder) view.getTag();
                }

                if ((items == null) || ((position + 1) > items.size()))
                    return view;

                objBean = items.get(position);


        holder.tv_event_name = (TextView) view.findViewById(R.id.tv_event_name);
        holder.tv_event_date = (TextView) view.findViewById(R.id.tv_event_date);
        holder.tv_event_start = (TextView) view.findViewById(R.id.tv_event_start);
        holder.tv_event_end = (TextView) view.findViewById(R.id.tv_event_end);
        holder.tv_event_location = (TextView) view.findViewById(R.id.tv_event_location);


        if (holder.tv_event_name != null && null != objBean.getName()
                && objBean.getName().trim().length() > 0) {
            holder.tv_event_name.setText(Html.fromHtml(objBean.getName()));

        }
        if (holder.tv_event_date != null && null != objBean.getDate()
                && objBean.getDate().trim().length() > 0) {
            holder.tv_event_date.setText(Html.fromHtml(objBean.getDate()));
        }
        if (holder.tv_event_start != null && null != objBean.getStartTime()
                && objBean.getStartTime().trim().length() > 0) {
            holder.tv_event_start.setText(Html.fromHtml(objBean.getStartTime()));
        }
        if (holder.tv_event_end != null && null != objBean.getEndTime()
                && objBean.getEndTime().trim().length() > 0) {
            holder.tv_event_end.setText(Html.fromHtml(objBean.getEndTime()));
        }
        if (holder.tv_event_location != null && null != objBean.getLocation ()
                && objBean.getLocation ().trim().length() > 0) {
            holder.tv_event_location.setText(Html.fromHtml(objBean.getLocation ()));

        }


        return view;
    }

    public class ViewHolder {
        public TextView 
        tv_event_name,
        tv_event_date,
        tv_event_start,
        tv_event_end,
        tv_event_location
        /*tv_event_delete_flag*/;


    }


}

Logcat:

06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :1
06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :6
06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :14
06-11 10:54:45.063: I/System.out(1692): item disalbed is at postion :15
06-11 10:54:45.073: I/System.out(1692): item disalbed is at postion :18
06-11 10:54:45.073: I/System.out(1692): results of delete list :[1, 6, 14, 15, 18]
06-11 10:54:45.073: I/System.out(1692): results of delete list a:[1, 6, 14, 15, 18]
06-11 10:54:45.073: I/System.out(1692):  set adapaer to list view called;
06-11 10:54:45.183: I/System.out(1692): background set to white at position 0

06-11 10:54:45.393: I/System.out(1692): background set to white at position 0
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0
06-11 10:54:45.393: I/System.out(1692): background set to white at position 0
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0
06-11 10:54:45.403: I/System.out(1692): background set to white at position 0
06-11 10:54:45.573: I/System.out(1692): background set to yellow at disable list 1
06-11 10:54:45.573: I/System.out(1692): background set to yellow at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to yellow at disable list 6
06-11 10:54:45.573: I/System.out(1692): background set to yellow at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to white at position 1
06-11 10:54:45.573: I/System.out(1692): background set to yellow at disable list 14
06-11 10:54:45.573: I/System.out(1692): background set to yellow at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to yellow at disable list 15
06-11 10:54:45.583: I/System.out(1692): background set to yellow at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to yellow at disable list 18
06-11 10:54:45.583: I/System.out(1692): background set to yellow at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.583: I/System.out(1692): background set to white at position 1
06-11 10:54:45.593: I/System.out(1692):  crash
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/System.out(1692): background set to white at position 2
06-11 10:54:45.623: I/Sys....3,4,....
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.163: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.173: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.183: I/System.out(1692): background set to white at position 5
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5
06-11 10:54:46.193: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.203: I/System.out(1692): background set to white at position 5
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to yellow at disable list 1
06-11 10:54:46.283: I/System.out(1692): background set to yellow at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to yellow at disable list 6
06-11 10:54:46.283: I/System.out(1692): background set to yellow at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to yellow at disable list 14
06-11 10:54:46.283: I/System.out(1692): background set to yellow at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.283: I/System.out(1692): background set to white at position 6
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6
06-11 10:54:46.293: I/System.out(1692): background set to yellow at disable list 15
06-11 10:54:46.293: I/System.out(1692): background set to yellow at position 6
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6
06-11 10:54:46.293: I/System.out(1692): background set to white at position 6
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6
06-11 10:54:46.303: I/System.out(1692): background set to yellow at disable list 18
06-11 10:54:46.303: I/System.out(1692): background set to yellow at position 6
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6
06-11 10:54:46.303: I/System.out(1692): background set to white at position 6
06-11 10:54:46.303: I/System.out(1692):  crash
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7
06-11 10:54:46.353: I/System.out(1692): background set to white at position 7
06-11 10:54:46.353: I/System.out(......

感谢您的帮助!


通过从视图中查找其 Id 来获取要更改背景的整行。现在设置您选择的背景...

从此链接获取进一步帮助..:

更改 Android 上 ListView 项目的背景颜色 https://stackoverflow.com/questions/2217753/changing-background-color-of-listview-items-on-android

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

根据自定义适配器中的条件更改特定行的背景 的相关文章

  • Android TelecomManager 中的 addIncomingCall 没有执行任何操作

    我正在尝试使用本机 Android 来电 UI 我有一个连接服务 并且我已经成功注册了一个电话帐户 但在我调用方法 addNewIncomingCall 后什么也没有发生 对我所缺少的有什么想法吗 显现
  • 通过代码在创建时突出显示 ListView 项目

    我想在创建 listView 时突出显示 ListView 的第一行 0 我尝试了不同的方法 就像您在注释代码中看到的那样 但没有任何效果 这很奇怪 因为 OnItemClickListener 中的突出显示工作正常 它通过 xml 选择器
  • 升级到最新支持库后Android JACK编译器错误

    Android Studio 2 2 3 Windows 10 64位 构建工具版本 25 Android Gradle插件版本2 2 3 升级到最新的支持库 从 23 4 0 到 25 1 0 并更改编译版本 从 23 到 25 后 我收
  • Android:如何暂停和恢复可运行线程?

    我正在使用 postDelayed 可运行线程 当我按下按钮时 我需要暂停并恢复该线程 请任何人帮助我 这是我的主题 protected void animation music6 music4 postDelayed new Runnab
  • 虚拟回调接口

    在 Eclipse 为您创建的来自 Google 的示例主从流代码中 片段中包含以下内容 private Callbacks mCallbacks sDummyCallbacks public interface Callbacks pub
  • 使用 proguard 混淆文件名

    我正在使用 proguard 和 Android Studio 混淆我的 apk 当我反编译我的apk时 我可以看到很多文件 例如aaa java aab java ETC 但我项目中的所有文件都有原始名称 有没有办法混淆我的项目的文件名
  • 我无法再在后台应用程序中接收任何 FCM 消息

    当应用程序处于后台时 我无法再在应用程序中接收任何数据消息 请注意 直到最近它在我的应用程序中都运行良好 也许在我的开发环境最近更新后它停止工作了 我不能说 所以我尝试用快速入门 android 项目 https github com fi
  • relativelayout导致动画不起作用?

    我有一个活动 其布局仅包含一个 VideoView 这是 XML
  • 自动删除 Firebase 通知

    我有一个问题 我都读过让通知在 5 分钟后消失 https stackoverflow com questions 15648699 make notification disappear after 5 minutes and 几秒钟后清
  • 如何使用 Google 的 GithubBrowserSample 方法在片段之间共享视图模型?

    我对 Android 架构组件的使用非常陌生 因此我决定使用 GithubBrowserSample 来构建我的应用程序来实现我的许多用例 但我有一个问题 我不知道使用这种方法在片段之间共享视图模型的正确方法是什么 我想共享视图模型 因为我
  • 更改语言 Flutter 的按钮

    我正在 Flutter 中构建一个应用程序 到目前为止 我正在使用 JSON 国际化 其中应用程序的语言基于用户手机中默认的语言 它工作得很好 但我想给用户有机会在不更改手机系统语言设置的情况下更改语言 只需单击按钮 然后应用程序即可更改语
  • Android 和 Google 地图内部片段以及其他控件和 viewpager

    我是android编程新手 我有一个带有 3 个页面 片段 的小应用程序 使用 pageradapter 和 viewpager 在它们之间滑动 其中一个页面包含复选框 和其他控件 和地图 我的问题是程序在启动时崩溃 Fragment co
  • 在 Android 中加密/解密字符串的简单方法

    我的问题是如何加密String String AndroidId Override public void onCreate Bundle savedInstanceState super onCreate savedInstanceSta
  • 模拟器无法加载

    我正在使用 hello android 教程并通过 eclipse 创建 avd 启动模拟器时不使用图像 它只是显示一个黑色的后屏 中间有 ANDROID 字样 并且在 ANDROID 字样的末尾有一个闪烁的光标 我已按照 T 的步骤安装
  • 如何在Android模拟器中隐藏应用程序图标?

    我有一个应用程序在启动完成后自动启动 但应用程序图标显示在android模拟器中 现在我想向用户隐藏该图标 这样用户就无法知道应用程序已启动 并且他们无法启动该应用程序手动申请 在您的 AndroidManifest xml 文件中 您可能
  • Android - 存储对ApplicationContext的引用

    我有一个静态 Preferences 类 其中包含一些应用程序首选项和类似的内容 可以在那里存储对 ApplicationContext 的引用吗 我需要该引用 以便我可以在不继承 Activity 的类中获取缓存文件夹和类似内容 你使用的
  • 如何将 JSON 数据从 Android 发送到 php url?

    我想将登录信息从我的应用程序发送到 php url 因为这我的应用程序将崩溃 任何人都可以帮助我解决这个问题 这是我的服务器登录方法 我想将数据发送到此登录方法 Method public method login Parameters 3
  • 使 Recyclerview 固定高度并可滚动

    已解决以下检查答案 所以我试图为我的 Android 应用程序创建评论功能 我想在 recyclerview 中显示评论 然后在 recyclerview 下方有一个按钮和文本视图来添加评论 我想让 recyclerview 具有一定的高度
  • Android:透明活动问题

    最近 在我们的一款生产应用程序上 透明活动已停止工作 我的意思是它变成了黑色背景而不是透明背景 当我将活动的背景颜色设置为纯色 即红色 绿色等 时 它的应用不会出现问题 该问题可能是由于迁移到 AndroidX 引起的 但我没有这方面的证据
  • 我想测量 ListView 的高度 (getHight() = 0)

    我无法自己决定任务将是问 我想测量 ListView 的高度 无法捕捉渲染 ListView 的时刻 rssListView getHight 0 public class RSSactivity extends Activity publ

随机推荐