グリッドビューとレイアウトインフレータを使用して、テキスト付きのアイコンを表示しています。
私は次のコードを参照しています:http: //mytelcoit.com/2010/02/programming-android-create-icon-with-text-using-gridview-and-layout-inflater/テキストはSDカードに保存されます。次のようになります。
私のテキストファイルには次のデータが含まれています。
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でcolumns値を使用する方法と、columns配列が正しいかどうかがわかりません。
これで私を助けてください
ありがとう
パンカイ