我在上面有一个微调器,显示圣经的书.选择一本书后,我会找出其中有几章,并将其放入Chapters变量中.然后,我想根据有多少章来更改名为bible_chapters的微调器.
public class Find extends Fragment {
private Spinner bibleBooks;
private Spinner bibleChapters;
private Spinner bibLeverses;
private boolean spinnerInitialized;
public Find() {
// required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_find, container, false);
final DatabaseManager databaseAccess = DatabaseManager.getInstance(getActivity());
final Context con = getContext();
// Spinner Listener
bibleBooks = rootView.findViewById(R.id.bible_books);
bibleChapters = rootView.findViewById(R.id.bible_chapters);
bibleBooks.setonItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if (!spinnerInitialized) {
spinnerInitialized = true;
return;
}
databaseAccess.open();
String book = adapterView.getSelectedItem().toString();
int Chapters = databaseAccess.howManyChapters(book);
databaseAccess.close();
Log.d("Chapters",String.valueOf(Chapters));
if(Chapters > 1) {
List<String> newChapters = new ArrayList<String>();
for (int x = 2; x <= Chapters; x++) {
newChapters.add("Chapter " + x);
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(con, bibleBooks, newChapters);
bibleBooks.setAdapter(arrayAdapter);
}
}
public void onnothingSelected(AdapterView<?> adapterView) {
return;
}
});
// Inflate the layout for this fragment
return rootView;
}
}
错误在于ArrayAdapter< String>. arrayAdapter = new ArrayAdapter< String>(con,bibleBooks,newChapters);线.问题在于上下文.我试过了:
这个,
rootView,
getContext(),
getActivity(),
我不断得到的错误是:
错误:找不到适用于ArrayAdapter(Context,Spinner,List< String>)的合适的构造函数
他们似乎都不是它要找的东西.我要去哪里错了?
解决方法:
在Xamarin.Android中,我总是传递spinnerItem,例如Android.Resource.Layout.SimpleSpinnerItem
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(con, Android.Resource.Layout.SimpleSpinnerItem, newChapters);
而不是微调框本身的* bibleBooks *.
编辑:
对于Java:android.R.layout.simple_spinner_item
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。