English 中文(简体)
Spinner 的提示没有显示项目
原标题:Prompt from Spinner is not showing the items

我刚刚为Android设计了一个应用软件 使用Eclipse, 一切正常, 然而,当我点击“旋转器”时, 提示看起来是空的, 但是值是空的, 因为我可以选择它们, 我能做些什么来让它们可见呢? 它在模拟器里起作用, 但不能在手机上起作用, 谢谢!

空白方块是提示, 值也在那里!

    String sqlSelect = "SELECT id, name, password FROM password";
    Cursor c = db.rawQuery(sqlSelect, null);            


    Spinner sp1 = (Spinner)findViewById(R.id.spinner1);
    ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    ad.setDropDownViewResource(android.R.layout.simple_spinner_item);
    sp1.setAdapter(ad);        

    System.out.println("Total of records is:" + c.getCount());

    if(c.moveToFirst()){
        int i = 0;

        while(c.moveToNext()){
            ad.add(c.getString(c.getColumnIndex("name")));              
            i++;
        }
    }        

布局 :

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <!-- Preview: listitem=@android:layout/simple_spinner_item -->
</Spinner>

在此显示图像 :

http://img163.imageshack.us/img 163/659/cap201205222344.jpg

最佳回答

我最后使用我的阵列Adapter的一个子类, 根据我发现的一个例子:

    ArrayAdapter<String> ad = new ArrayAdapter<String>(this,        android.R.layout.simple_spinner_item){
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            View view = super.getDropDownView(position, convertView, parent);

            TextView text = (TextView)view.findViewById(android.R.id.text1);
            text.setTextColor(Color.BLUE);

            return view;
        }           
    };

现在,我可以看到这些物品, 但我仍然想知道为什么我能看到模拟器上的东西,

问题回答

在您张贴的图像中,您的旋转器正在显示一些行,这意味着它从数据库中获取值,但您必须改变旋转器项目的背景颜色。

文本大小和背景大小都是白色的, 所以您无法在 spinner 视图中查看文本, 所以尝试使用自定义的适配器创建 spinner 或更改 spinner 项 :

ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

您可以使用 通知DataSet Changed () , 这应该引起脊柱的重新绘制 。

if(c.moveToFirst()){  
    int i = 0;  
    while(c.moveToNext()){  
        ad.add(c.getString(c.getColumnIndex("name")));                
        i++;  
}  
ad.notifyDataSetChanged();




相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签