2011-06-28 7 views
0

ギャラリーの画像の名前をクリックして表示するにはどうすればいいですか?ギャラリー内の画像の名前をクリックして表示する方法は?

私の画像の配列を作成し、/ sdcard/CameraExample/28.06.2011_11-23-54.bmpを取得しましたが、17のうち1つしか表示されません。ディレクトリファイルを削除する方法、その名前だけを残す。どのように配列内の各ピクチャにgetnameを割り当てるのですか?

これは私のサンプルコードです。あなたがラベルにファイルの名前を設定する代わりに、そのpostionを設定する必要があります

Gallery g = (Gallery) findViewById(R.id.Gallery01); 
g.setAdapter(new ImageAdapter(this, ReadSDCard())); 

final TextView label2 = (TextView)findViewById(R.id.TextView01); 

final TextView label = (TextView)findViewById(R.id.textView1); 
label.setText("Фото 0 из" + g.getAdapter().getCount()); 

g.setOnItemClickListener(new OnItemClickListener() { 
    public void onItemClick(AdapterView<?> parent, 
     View v, int position, long id) { 


     label.setText("Фото"+" "+ ++position + " из " + parent.getCount()); 

     String dirPath = "/sdcard/CameraExample/"; 
     File f = new File(dirPath); 
     File[] files = f.listFiles(); 


     for(int i=0; i < files.length; i++) 
     { 
      File file = files[i]; 
      String fileName = file.getName(); 
      if (i == position) 
      { 

      label2.setText(fileName); 
      } 




     } 

    } 
}); 

おかげ

答えて

0

デュード。

は、ここの上にコードをチェックしてください:

label.setText("Photo" + ++position + " of " + parent.getCount() + file); 

にこれを変更するよう: -

String fileName = file.getName(); 
label.setText("Viewing file: " + fileName); 

これはあなたのために働く必要があります。

関連する問題