简体   繁体   English

从Imagebutton打开特定的图像和文件夹,但仍然可以滑动到目录中的其他图像和文件夹吗?

[英]Open specific image and folder from Imagebutton, but still swipe to others in the directory?

so I am (slowly!!) getting the hang of android, but the following is confusing me; 所以我(慢慢地!)正在掌握android的功能,但是以下内容使我感到困惑;

I want to open a specific image file when the user clicks on an image button, i am using this code: 当用户单击图像按钮时,我想打开一个特定的图像文件,我正在使用以下代码:

 Intent showchart = new Intent(); 
 showchart.setAction(Intent.ACTION_VIEW);
 showchart.setDataAndType(Uri.parse("file:///sdcard/1m.jpg"), "image/*");
 startActivity(showchart);

and it is working fine. 而且工作正常。 I would like to be able to swipe as per the gallery app to the next image without having to go back to my app, but it is not working, even though there are lots of images in the directory. 我希望能够按图库应用程序滑动到下一张图像,而不必返回到我的应用程序,但是即使目录中有很多图像,它也无法正常工作。

Help well received! 帮助得到好评!

===================edit=================================================== ===================编辑=============================== =====================

i found this code from google that seems closer to what i need, but how should i modify it to oen just the one file i want? 我从Google找到了看起来更接近我需要的这段代码,但是我应该如何对其进行修改以仅生成我想要的一个文件?

TextView textTargetUri;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  Button buttonLoadImage = (Button)findViewById(R.id.loadimage);
  textTargetUri = (TextView)findViewById(R.id.targeturi);

  buttonLoadImage.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
 // TODO Auto-generated method stub
 Intent intent = new Intent(Intent.ACTION_PICK,
 android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
 startActivityForResult(intent, 0);
 }});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);

if (resultCode == RESULT_OK){
Uri targetUri = data.getData();
textTargetUri.setText(targetUri.toString());
}
  }
   }

i have not come across the result ok / onactivity result stuff before, im guessing i should be able to edit that textview to the path i want and update the string to reflect a value loaded when the user clicks one of my imagebuttons? 我之前还没有遇到过ok / onactivity结果的东西,我想我应该能够将textview编辑到我想要的路径,并更新字符串以反映当用户单击我的imagebutton时加载的值?

What is understood is you are trying to open a galley from your app and selecting an image. 可以理解的是,您正在尝试从应用程序打开厨房并选择图像。 Check out this link, it could be a lot of help. 查看此链接,可能会有很多帮助。

Get/pick an image from Android's built-in Gallery app programmatically 以编程方式从Android的内置Gallery应用程序获取/选择图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM