2015-10-19 95 views
0

我试图将我在微调器中定义的值传递给ListView。我的意思是当你从ListView中显示的这个微调器中选择一个项目。如何将Spinner的值传递给ListView?

@Override 
public void onItemSelected(AdapterView<?> arg0, View arg1,int posicion, long arg3) { 
    String valor = spinner_datos[posicion].toString();     
    adapter.add(valor); 
    list.setAdapter(adapter);     
} 

回答

2

使用adapter.notifyDataSetChanged()的adapter.add(勇气)之后;

@Override 
public void onItemSelected(AdapterView<?> arg0, View arg1,int posicion, long arg3) { 
    String valor = spinner_datos[posicion].toString(); 
    adapter.add(valor); 
    adapter.notifyDataSetChanged(); //This will notify the adapter to redraw it's views, updating the list so that you can see the changes   
} 

你并不需要调用list.setAdapter(adapter);再次

+0

还好吧感谢ü。但问题是,当我尝试运行白色代码时,应用程序停止。所以我现在不怎么做,我想知道是否有另一种方式来做到这一点。 –

+0

你应该在你的'onCreate'方法上设置'list.setAdapter(adapter);' – NaviRamyle