0
我试图创建一个Spinner
,该数据填充了我从一个文本文件读取的Java中创建的Array
的数据。如何用我在Java中创建的数组填充微调框?
(这就是所谓的pokemon.txt,所以这720项..这将是愚蠢的输入那些独立,所以我觉得用一个文本文件,读取距离,这将是最佳的。)
Spinner spinner;
public static void main(String[] args) throws IOException {
List<String> lines = new ArrayList<String>();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("pokemon.txt"));
String line = null;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
} finally {
reader.close();
}
String[] array = (String[]) lines.toArray();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
Typeface Dotum = Typeface.createFromAsset(getAssets(),"fonts/gulim.ttc");
TextView myTextView = (TextView)findViewById(R.id.jingenMenu1);
myTextView.setTypeface(Dotum);
spinner=(Spinner) findViewById(R.id.pkmnSel1);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, , android.R.layout.simple_spinner_item); //I know it's missing the source but, that's where I'm
spinner.setAdapter(adapter); //lost because I can't figure out how to populate it with my array.
}
我了解我的代码可能非常混乱和/或不正确,但是,这有点凌驾于我的头脑之上,所以我非常希望得到尽可能多的信息。
如果有更简单的方法,甚至可能是将文件直接读入XML数组的方式,那么请随时告诉我。任何帮助。
感谢您的阅读,并且非常感谢您的提前。
Android与Java不同。没有'main()'入口点。你需要在'onCreate()'的其他地方调用这个代码,然后你可以在数组填充后加载你的微调器。 – codeMagic
Oooooooh!我懂了!这意味着很多。我非常感谢你的帮助。 :d – searequiem