I want to list all the images of a directory and read one at a time. The directory location will be given from a input field.
public class MainActivity extends AppCompatActivity {
// on below line we are creating variable for image view.
ImageView imageIV;
Button viewButton;
EditText inputFolder;
HorizontalScrollView horizontalScrollView;
TextView textView1;
String name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewButton = (Button)findViewById(R.id.viewButton);
horizontalScrollView = (HorizontalScrollView)findViewById(R.id.horizontalScrollView);
inputFolder = (EditText)findViewById(R.id.inputFolder);
viewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
inputFolder = (EditText)findViewById(R.id.inputFolder);
textView1 = (TextView)findViewById(R.id.textView1);
textView1.setText(inputFolder.getText().toString());
}
});
// on below line we are creating an image file and
// specifying path for the image file on below line.
name = inputFolder.getText().toString();
File imgFile = new File("/storage/emulated/0/Pictures/Screenshots/Screenshot_20220912-174402.jpg");
// on below line we are initializing variables with ids.
imageIV = (ImageView)findViewById(R.id.idIVImage);
// on below line we are checking if the image file exist or not.
if (imgFile.exists()) {
// on below line we are creating an image bitmap variable
// and adding a bitmap to it from image file.
Bitmap imgBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
// on below line we are setting bitmap to our image view.
imageIV.setImageBitmap(imgBitmap);
}
}
}
I am using above code for the same, but unable to feed output of the input field to list all the image files.