2016-03-22 7 views
0

ギャラリーにアプリケーションを表示する方法を知っている人は誰でもクリックしてimageViewにアップロードし、その後はAPIを使用してアップロードします。しかし、私はこれをどのように達成するのですか? Btw im申し訳ありませんが、私は理解しやすい何かを見つけることができなかった、私はちょうどアンドロイドアプリケーションを開発し始めた。アンドロイドギャラリーにアプリケーションを表示してからImageViewで選択した画像をアップロードする

詳細情報が必要な場合は

+0

http://www.androidinterview.com/android-gallery-view-example-displaying-a-list -of-images/,,,,,,このリンクを参照 –

+0

私はあなたがしたことを作ったが、これはdrawableから取得する方法を教えてくれるが、画像をその画像ビューに読み込むにはどうすればよいですか?どのように写真を撮った直後にそれを取得するのですか? –

答えて

0
public class MainActivity extends AppCompatActivity { 
    private ImageButton btn; 
    private ImageView imageView; 
    private static int RESULT_LOAD_IMAGE = 1; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     btn=(ImageButton)findViewById(R.id.imageButton); 
     btn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
       startActivityForResult(i, RESULT_LOAD_IMAGE); 
      } 
     }); 
    } 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { 
      Uri selectedImage = data.getData(); 
      String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

      Cursor cursor = getContentResolver().query(selectedImage, 
      filePathColumn, null, null, null); 
      cursor.moveToFirst(); 
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      String picturePath = cursor.getString(columnIndex); 
      cursor.close(); 

      imageView = (ImageView) findViewById(R.id.imgView); 
     imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

     } 
    } 
} 

//自分でmain.xmlを管理

+0

これを実装する方法やmain.xmlに何を入れるべきかについての説明がありますか? –

+0

main.xmlが添付されました。 を見て実装してください。 –

+0

複数の画像を選択できません。私がそうするなら、それはクラッシュ編集:それは毎回クラッシュする –

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" 
android:orientation="vertical"> 

    <ImageButton 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageButton" 
    android:layout_gravity="center_horizontal" /> 

    <ImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView" 
    android:layout_gravity="center_horizontal" /> 
</LinearLayout> 
関連する問題