如何从SD卡检索文本并相应地设置文本视图?
|
我正在使用gridview和布局充气器显示带有文本的图标。
我指的是以下网址提供的代码:http://mytelcoit.com/2010/02/programming-android-create-icon-with-text-using-gridview-and-layout-inflater/,但图片和文本存储在sdcard中。它看起来应该像这样:
我的文本文件包含以下数据:
Profile 0|Profile 1|Profile 2
我正在使用以下代码:
public View getView(final int position, View convertView, ViewGroup parent) {
View v;
//String text;
final ImageView picturesView;
if (convertView == null) {
LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.icon, null);
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,\"string.txt\");
//StringBuilder stext = new StringBuilder();
TextView tv = (TextView)v.findViewById(R.id.icon_text);
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
String[] columns = line.split(\"\\\\|\");
for (String name : columns){
tv.setText(name);
}
//stext.append(line);
//stext.append(\'\\n\');
}
}
catch (IOException e) {
//You\'ll need to add proper error handling here
}
tv.setTextSize(12);
tv.setTextColor(Color.BLACK);
}
else {
v = convertView;
}
}
我想用字符串值设置文本视图
TextView tv = (TextView)v.findViewById(R.id.icon_text);
tv.setText();
我试图通过Toast.makeText(SDCardImagesActivity.this, \"\"+columns.length, Toast.LENGTH_LONG).show();
检查列的长度,但显示为1(5次)
我很困惑如何在tv.setText中使用column值,以及column数组是否正确。
请帮我
谢谢
潘卡伊
没有找到相关结果
已邀请:
4 个回复
炉挤仙挟
代替这条线...
...使用以下内容...
痰降锭骂奸
嘘伪
谢谢 迪帕克
讹巳漓把备
。
谢谢 迪帕克