在我的应用中,我正在尝试修复一个微调器,该微调器将位置详细信息显示为下拉列表。位置存储在“房间”数据库表的列中。我无法检索Strings的单个列并将其填充到Spinner中。
表注释;
@ColumnInfo(name = "locations")
private String locations;
道:
@Query("SELECT locations FROM `table-note`")
List<String> getAllLocations();
主要活动:
final List<String> locationList = noteDatabase.noteDao().getAllLocations();
final ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
this,R.layout.spinner_item,locationList){
@Override
public boolean isEnabled(int position){
if(position == 0)
{
return false;
}
else
{
return true;
}
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
View view = super.getDropDownView(position, convertView, parent);
TextView tv = (TextView) view;
if(position == 0){
tv.setTextColor(Color.GRAY);
}
else {
tv.setTextColor(Color.BLACK);
}
return view;
}
};
spinnerArrayAdapter.setDropDownViewResource(R.layout.item_spinner);
spinner.setAdapter(spinnerArrayAdapter);