我正在使用 gridview 和 layout inflater 来显示带有文本的图标。
我指的是以下代码: 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 中使用列值以及列数组是否正确。
请帮助我
谢谢
潘卡伊