从游标数据添加到与SimpleCursorAdapter的ListView显示白色文本(如何使它黑)游标、使它、文本、白色

2023-09-07 04:10:16 作者:從頭洅唻

从游标数据添加到与SimpleCursorAdapter的ListView显示白色文本(如何使它黑色) - 看到的图像

下面是简单的游标适配器code

 公共无效displayWords(光标C){    //创建一个新的SimpleCursorAdapter    SimpleCursorAdapter mCursorAdapter =新SimpleCursorAdapter(        getApplicationContext()//应用程序的快捷对象        android.R.layout.simple_list_item_1,//在XML中的布局一行在ListView        C,//从查询结果        新的String [] {} DatabaseTable.COL_WORD,//在游标的列名的字符串数组        新的INT [] {android.R.id.text1}); //视图ID的整数数组中的行布局    //设置适配器为ListView    setListAdapter(mCursorAdapter);    / *使用SimpleCursorAdapter从数据库获取数据。     * stackoverflow.com/questions/12077955/android-using-simplecursoradapter-to-get-data-from-database-to-listview     * /} 

而在AndroidManifes文件中使用的样式资源

 <样式名称=AppBaseTheme父=机器人:Theme.Holo.Light.DarkActionBar>    <! -  14 API自定义主题可以去这里。 - >< /风格><样式名称=AppBaseTheme父=机器人:Theme.Holo.Light>    <! -  11 API自定义主题可以去这里。 - >< /风格>   <样式名称=AppBaseTheme父=机器人:Theme.Light>    <! -         在新API的级别可以去提供自定义主题        RES /值-VXX / styles.xml,而自定义相关        向后兼容性可以去这里。     - >< /风格><! - 应用的主题。 - ><样式名称=AppTheme父=AppBaseTheme>< /风格> 

解决方案

像叶戈尔说,如果你能告诉更多code,这将是有益的。

在LabVIEW中,怎样能够将图片中两个游标的位置读取出来,自动计算两游标之间位置的差值呢

在其间:它看起来像您使用的是有一个'光'(全息)的主题,而您的应用程序(或只是活动()采用了暗(全息)主题列表视图项目。的textviews文本的颜色是由回升在白色背景顶部的应用程序的黑暗的主题(白色字体颜色)。

要弄清楚为什么出现这种情况,我们需要更多的code(AndroidManifest.xml中,例如)从你的。

OP的评论后更新:

 公共无效displayWords(光标C){    //创建一个新的SimpleCursorAdapter    SimpleCursorAdapter mCursorAdapter =新SimpleCursorAdapter(        getApplicationContext()//应用程序的快捷对象        android.R.layout.simple_list_item_1,//在XML中的布局一行在ListView        C,//从查询结果        新的String [] {} DatabaseTable.COL_WORD,//在游标的列名的字符串数组        新的INT [] {} android.R.id.text1){        @覆盖        公共查看NewView的(上下文的背景下,光标光标的ViewGroup父){            查看NewView的= super.newView(背景下,游标,父母);            ((的TextView)newView.findViewById(android.R.id.text1))setTextColor(Color.BLACK)。返回NewView的;        }    }; //视图ID的整数数组中的行布局    //设置适配器为ListView    setListAdapter(mCursorAdapter);    / *使用SimpleCursorAdapter从数据库获取数据。     * stackoverflow.com/questions/12077955/android-using-simplecursoradapter-to-get-data-from-database-to-listview     * /  } 

我添加的覆盖适配器的的 NewView的的方式到code,这样可以让你设置/更改文本的颜色。尝试一下,看看它是否工作。

Data from Cursor added to ListView with SimpleCursorAdapter shows white text (how to make it black) - see the image

Here is the Simple cursor adapter code

public void displayWords(Cursor c){

    // Creates a new SimpleCursorAdapter
    SimpleCursorAdapter mCursorAdapter = new SimpleCursorAdapter(
        getApplicationContext(),                    // The application's Context object
        android.R.layout.simple_list_item_1,        // A layout in XML for one row in the ListView
        c,                                          // The result from the query
        new String[] {DatabaseTable.COL_WORD},      // A string array of column names in the cursor
        new int[] { android.R.id.text1 });          // An integer array of view IDs in the row layout


    // Sets the adapter for the ListView
    setListAdapter(mCursorAdapter);

    /* Using SimpleCursorAdapter to get Data from DB.
     * stackoverflow.com/questions/12077955/android-using-simplecursoradapter-to-get-data-from-database-to-listview
     */
}

And the style resources used in AndroidManifes file

   <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>

<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 11 theme customizations can go here. -->
</style>

   <style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>

解决方案

Like Egor said, if you could show some more code, that would be helpful.

In the meantime: It looks like you are using list-view items that have a 'light' (holo) theme while your app (or just that activity() uses a 'dark' (holo) theme. The textviews' text-color is picked up from the app's dark theme (white font color) on top of white background.

To figure out why that happens, we need more code (AndroidManifest.xml, for example) from you.

Update after OP's comment:

public void displayWords(Cursor c){

    // Creates a new SimpleCursorAdapter
    SimpleCursorAdapter mCursorAdapter = new SimpleCursorAdapter(
        getApplicationContext(),                    // The application's Context object
        android.R.layout.simple_list_item_1,        // A layout in XML for one row in the ListView
        c,                                          // The result from the query
        new String[] {DatabaseTable.COL_WORD},      // A string array of column names in the cursor
        new int[] { android.R.id.text1 }){
        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            View newView = super.newView(context, cursor, parent);
            ((TextView)newView.findViewById(android.R.id.text1)).setTextColor(Color.BLACK);
return newView;
        }
    };          // An integer array of view IDs in the row layout


    // Sets the adapter for the ListView
    setListAdapter(mCursorAdapter);

    /* Using SimpleCursorAdapter to get Data from DB.
     * stackoverflow.com/questions/12077955/android-using-simplecursoradapter-to-get-data-from-database-to-listview
     */
  }

I added an override of the adapter's newView method to your code, which would allow you to set/change the text's color. Try it and see if it works.