Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this..</p> <p>main.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/mainLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Button" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>activity class..</p> <pre><code>import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; public class MainActivity extends Activity { LinearLayout mainLinearLayout; Button button; Bitmap bmp; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mainLinearLayout = (LinearLayout)findViewById(R.id.mainLayout); button = (Button)findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub openGallery(); } }); } private void openGallery() { Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); } protected void onActivityResult(int requestCode, int resultcode, Intent intent) { super.onActivityResult(requestCode, resultcode, intent); if (requestCode == 1) { if (intent != null &amp;&amp; resultcode == RESULT_OK) { Uri selectedImage = intent.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 filePath = cursor.getString(columnIndex); cursor.close(); if(bmp != null &amp;&amp; !bmp.isRecycled()) { bmp = null; } bmp = BitmapFactory.decodeFile(filePath); ImageView imageView = new ImageView(MainActivity.this); imageView.setImageBitmap(bmp); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(100,100); imageView.setLayoutParams(lp); mainLinearLayout.addView(imageView,lp); } else { Log.d("Status:", "Photopicker canceled"); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload