我在上面有一个微调器,显示圣经的书.选择一本书后,我会找出其中有几章,并将其放入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
以上是内存溢出为你收集整理的android-从Spinner onItemSelected更改Spinner选项全部内容,希望文章能够帮你解决android-从Spinner onItemSelected更改Spinner选项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)