【问题标题】:Change Listview color on every 20seconds每 20 秒更改一次 Listview 颜色
【发布时间】:2012-09-14 16:01:43
【问题描述】:

是否可以每 10 或 15 秒更改一次列表视图颜色或背景颜色。我已为此列表视图使用现有代码。在 mycode 中添加必要步骤的位置。我不想每次选择项目时都为用户更改颜色。如果用户简单地打开我的应用程序并在 10 秒后自动更改背景颜色。

我的代码:

public class MainActivity extends Activity {
    private ListView lv;
    private EditText et;
    private String listview_array[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE",
    "SIX", "SEVEN", "EIGHT", "NINE", "TEN" };
    private ArrayList<String> array_sort= new ArrayList<String>();
    int textlength=0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lv = (ListView) findViewById(R.id.ListView01);
        et = (EditText) findViewById(R.id.EditText01);
        lv.setAdapter(new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1, listview_array));

        et.addTextChangedListener(new TextWatcher()
        {
        public void afterTextChanged(Editable s)
        {
                                                                        // Abstract Method of TextWatcher Interface.
        }
        public void beforeTextChanged(CharSequence s,
        int start, int count, int after)
        {
        // Abstract Method of TextWatcher Interface.
        }
        public void onTextChanged(CharSequence s,
        int start, int before, int count)
        {
        textlength = et.getText().length();
        array_sort.clear();
        for (int i = 0; i < listview_array.length; i++)
        {
        if (textlength <= listview_array[i].length())
        {
        if(et.getText().toString().equalsIgnoreCase(
        (String)
        listview_array[i].subSequence(0,
        textlength)))
        {
                                                                                                                        array_sort.add(listview_array[i]);
                                                                                                        }
                                                                                        }
                                                                        }
        lv.setAdapter(new ArrayAdapter<String>
        (MainActivity.this,
        android.R.layout.simple_list_item_1, array_sort));
        }
        });

    }

【问题讨论】:

  • 可以使用自定义适配器......

标签: android android-listview background-color


【解决方案1】:

在 customview 的 getview() 中更改您正在膨胀的文本视图的颜色。 并在每次需要时使用 notifydatasetchanged()

【讨论】:

    猜你喜欢
    • 2020-11-05
    • 1970-01-01
    • 2022-11-10
    • 2014-12-31
    • 2015-03-02
    • 2021-06-17
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    相关资源
    最近更新 更多