0

How to show the name of the picture in the gallery by clicking on it?

i made an array of my images and I get the / sdcard / CameraExample / 28.06.2011_11-23-54.bmp, but it displays only 1 of 17. I would like to know how to remove a directory file, leaving only its name. and how do I assign getname each picture in the array?

it's my sample code.

 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);
            }




        }

    }
});  

Thanks

1 Answer 1

0

Dude you should be setting the name of the file in the label instead of setting its postion.

Check your code over here:

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

Modify this to as:-

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

This should work for you.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.