从文本文件的android负荷微调 [英] load spinner from text file android
本文介绍了从文本文件的android负荷微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个项目中工作,以填补从文本文件中微调的资产或SD卡。我的code是
i'm working on a project to fill spinner from text file in assets or sdcard. My code is
BufferedReader in = new BufferedReader(new FileReader("product.txt"));
String line = in.readLine();
int index = 0;
while (line != null) {
str[index++] = line;
line = in.readLine();
}
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, str);
spinner.setAdapter(adapter);
和main.xml中
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
任何人都可以请帮我解决这个问题呢?在此先感谢
Can anyone please help me to solve this issue? Thanks in advance
推荐答案
如果你的文件是在资产文件夹你的项目,我认为你必须做的:
If your file is in the assets folder of you project, I think you have to do:
Vector<String>str=new Vector<String>();
BufferedReader in = new BufferedReader(new InputStreamReader(getAssets().open("product.txt"));
String line = in.readLine();
int index = 0;
while (line != null) {
str.add(line);
line = in.readLine();
}
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, str);
spinner.setAdapter(adapter);
然后你右键点击Eclipse中的资产目录,然后选择构建路径 - >用作源文件夹。
Then you have to right click on the assets directory in Eclipse then choose Build Path -> Use as Source Folder.
这篇关于从文本文件的android负荷微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文