I'm using a LayoutInflater to retrieve a view from the resources, then insert it into a programmaticly constructed custom ViewGroup. It works fine when the resource contains only a TextView. But when the resource contains a LinearLayout it fails quietly - no exception is thrown, the custom ViewGroup components appear but the View from the resource does not appear.
The custom ViewGroup puts coloured borders around an inner View. Here is the class:
package ask.question;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
public class BorderViewGroup extends ViewGroup {
private View leftBorder ;
private View topBorder ;
private View rightBorder ;
private View bottomBorder ;
private View innerView = null ;
public BorderViewGroup(Context context) {
super(context);
initBorderViewGroup(context);
}
public BorderViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
initBorderViewGroup(context);
}
public BorderViewGroup(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initBorderViewGroup(context);
}
private void initBorderViewGroup(Context context) {
leftBorder = new View(context);
topBorder = new View(context);
rightBorder = new View(context);
bottomBorder = new View(context);
addView(leftBorder);
addView(topBorder);
addView(rightBorder);
addView(bottomBorder);
}
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// Should probably use argument 'changed'.
int width = r - l;
int height = this.getHeight();
leftBorder.layout(0, 0, 2, height);
topBorder.layout(0, 0, width, 2);
rightBorder.layout(width-2, 0, width, height);
bottomBorder.layout(0, height-2, width, height);
if (innerView != null) {
innerView.layout(2, 2, width-2, height-2);
}
}
/*
* Sets the view to be displayed within the borders.
* Subsequent calls will replace the view.
* #param view View to be displayed. May be null.
*/
public void setInnerView(View view) {
if (innerView!=null) {
this.removeView(innerView);
}
this.innerView = view ;
if (innerView!=null) {
addView(innerView);
}
}
/*
* Sets the colors for each of the four borders.
* A color value of zero will be ignored, leaving that border unchanged.
* Note: colors can be specified in hexadecimal. Red is 0xFFFF0000. In general, the first two hex digits control transparency, the next red, green and blue.
*/
public void setBorderColors(int leftColor, int topColor, int rightColor, int bottomColor) {
if (leftColor!=0) leftBorder.setBackgroundColor(leftColor);
if (topColor!=0) topBorder.setBackgroundColor(topColor);
if (rightColor!=0) rightBorder.setBackgroundColor(rightColor);
if (bottomColor!=0) bottomBorder.setBackgroundColor(bottomColor);
}
/*
* Sets the color of the border around the innerView.
* A color value of zero will be ignored, leaving the border unchanged.
* Note: colors can be specified in hexadecimal. Red is 0xFFFF0000. In general, the first two hex digits control transparency, the next red, green and blue.
*/
public void setBorderColor(int color) {
setBorderColors(color, color, color, color);
}
}
It works fine when the resource is a TextView. Here is the Activity's onCreate() method, and the resource file flat.xml.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BorderViewGroup bvg = new BorderViewGroup(this);
LayoutInflater inflater = LayoutInflater.from(this);
//View mainView = inflater.inflate(R.layout.flat, null);
View mainView = inflater.inflate(R.layout.nested, null);
View objectView = mainView.findViewById(R.id.object_view);
if (mainView==null) throw new RuntimeException("mainView is null");
if (objectView==null) throw new RuntimeException("objectView is null");
bvg.setBorderColors(0xFFFF0000, 0xFF00F0F0, 0xFF00FF00, 0xFF0000FF);
setContentView(bvg);
bvg.setInnerView(objectView);
}
and
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/object_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="View from resource xml." />
The above works fine. It displays coloured borders, and the text "View from resource xml.".
But it fails quietly if the resource file contains a LinearLayout. Here is the Activity's onCreate() method, and the resource file nested.xml.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BorderViewGroup bvg = new BorderViewGroup(this);
LayoutInflater inflater = LayoutInflater.from(this);
View mainView = inflater.inflate(R.layout.flat, null);
//View mainView = inflater.inflate(R.layout.nested, null);
View objectView = mainView.findViewById(R.id.object_view);
if (mainView==null) throw new RuntimeException("mainView is null");
if (objectView==null) throw new RuntimeException("objectView is null");
bvg.setBorderColors(0xFFFF0000, 0xFF00F0F0, 0xFF00FF00, 0xFF0000FF);
setContentView(bvg);
bvg.setInnerView(objectView);
}
and
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/object_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A TextView from resource XML." />
<TextView
android:id="#+id/here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="A second TextView." />
</LinearLayout>
This does not work. It displays the coloured borders, but not the text.
Why does one work, and not the other? Even better, how can the LinearLayout be made to work?
I've followed the inflater code from XML Inflater not seeing any of the views?. I've removed some arguments from the inflation because they cause already-have-parent errors. The TextView works without them.
Related
I would like to make a function to intercept a certain scroll at the top of the view.
to do this I'm trying to use OnScrollChangeListener.
My view contains a ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollViewClientPhysique"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/fond"
tools:context=".client.FicheClient">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">**strong text**
and I initialize addOnScrollChangedListener in a function I call inside onCreateView
fun initializeInfiniteScroll(){
val scrollView = myView.findViewById<View>(R.id.scrollViewClientPhysique) as ScrollView
scrollView.viewTreeObserver.addOnScrollChangedListener {
if (scrollView != null) {
val view = scrollView.getChildAt(scrollView.childCount - 1)
val diff =
view.bottom + scrollView.paddingBottom - (scrollView.height + scrollView.scrollY)
if (diff == 0) {
// do stuff
}
}
}
}
but when when I scroll the view I don't enter addOnScrollChangedListener to intercept how many dp the scroll is.
what am I doing wrong?
Please update your ScrollChangedListener as mentioned below.
public class MainActivity extends AppCompatActivity implements View.OnTouchListener,
ViewTreeObserver.OnScrollChangedListener {
ScrollView scrollView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scrollView = findViewById(R.id.scrollView);
scrollView.setOnTouchListener(this);
scrollView.getViewTreeObserver().addOnScrollChangedListener(this);
}
public void onScrollChanged(){
View view = scrollView.getChildAt(scrollView.getChildCount() - 1);
int topDetector = scrollView.getScrollY();
int bottomDetector = view.getBottom() - (scrollView.getHeight() + scrollView.getScrollY());
//TODO: Just added for testing/understanding. Please add/replace your own logic..
if(bottomDetector == 0 ){
Toast.makeText(this,"Scroll View bottom reached",Toast.LENGTH_SHORT).show();
}
if(topDetector <= 0){
Toast.makeText(this,"Scroll View top reached",Toast.LENGTH_SHORT).show();
}
}
#Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
}
There are what appear to be several clones of the same answer for the first version of Exoplayer and the original Android media player, but they do not compile on Exoplayer2, which reorganized quite a bit of the internal code.
A reasonably-diligent search has not found anything in the way of a library or example code to do this (e.g. pinch zoom and scroll, etc.) There's plenty of code around to do it for still images (e.g. retrieved through Picasso, etc)
Does anyone have a sample that will build and work with ExoPlayer2?
Thanks in advance!
Update: The problem appears to be that I cannot either subclass or attach a VideoListener to a SimpleExoPlayer instance; attempting to do so leaves you with nothing, as the instance has already attached its own listener which pays exactly zero attention to aspect ratio when a TextureView is involved. This makes the video completely unusable; a listener could correct that quite easily, but there appears to be no way to attach it (the methods to do so are marked deprecated, and if you try to use them anyway you get no video output.)
This code will paint and run the ua.pohohalo.zoomabletextureview (or just a plain TextureView) but I cannot attach a videolistener to it and the default, when it initializes, fits the video to the view size vertically in portrait mode which destroys the aspect ratio. It also has serious glitches if you resize the video below the display window size but I can test for and fix that in polohalo's code. What I've not figured out how to do is to get the original display to honor the original aspect ratio or to attach a VideoListener to set it on init -- it works fine if I use a PlayerView, but that's not able to be extended to support translations. The "VideoListener" prototype in this codeblock should fix the aspect ratio problem -- that's what I've been unable to attach or find a way to set a flag on the original view (which would also do the job) that tells ExoPlayer to honor the original aspect ratio and fit within the screen size.
The call to simpleExoPlayerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT), which works on a PlayerView, is not valid on a TextureView -- it appears that the mode defaults to RESIZE_MODE_FILL and I cannot find a method to set it to FIT.
package net.cudasystems.android.videotest;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.TextureView;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener;
public class MainActivity extends AppCompatActivity {
private String mURL = "http://point-at-an-mp4-file";
TextureView mPlayerView;
SimpleExoPlayer player = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPlayerView = findViewById(R.id.video_view2);
}
private void initializePlayer() {
DefaultRenderersFactory renderersFactory =
new DefaultRenderersFactory(this, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
VideoListener mVideoListener = new VideoListener() {
#Override
public void onRenderedFirstFrame() {
}
#Override
public void onVideoSizeChanged(int width, int height, int rotation, float pixelWidthHeightRatio ) {
String TAG = "VideoSizeChange";
int viewWidth = mPlayerView.getWidth();
int viewHeight = mPlayerView.getHeight();
double aspectRatio = (double) height / width;
int newWidth, newHeight;
if (viewHeight > (int) (viewWidth * aspectRatio)) {
// limited by narrow width; restrict height
newWidth = viewWidth;
newHeight = (int) (viewWidth * aspectRatio);
} else {
// limited by short height; restrict width
newWidth = (int) (viewHeight / aspectRatio);
newHeight = viewHeight;
}
int xoff = (viewWidth - newWidth) / 2;
int yoff = (viewHeight - newHeight) / 2;
Log.v(TAG, "video=" + width + "x" + height +
" view=" + viewWidth + "x" + viewHeight +
" newView=" + newWidth + "x" + newHeight +
" off=" + xoff + "," + yoff);
Matrix txform = new Matrix();
mPlayerView.getTransform(txform);
txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
txform.postTranslate(xoff, yoff);
mPlayerView.setTransform(txform);
}
};
player = ExoPlayerFactory.newSimpleInstance(
renderersFactory,
new DefaultTrackSelector(), new DefaultLoadControl());
player.setVideoTextureView(mPlayerView);
// mPlayerView.setPlayer(player);
player.setPlayWhenReady(true);
Uri uri = Uri.parse(mURL);
MediaSource mediaSource = buildMediaSource(uri);
player.prepare(mediaSource, true, true);
}
private MediaSource buildMediaSource(Uri uri) {
return new ExtractorMediaSource.Factory(
new DefaultHttpDataSourceFactory("exoplayer-codelab")).
createMediaSource(uri);
}
#Override
public void onStart() {
super.onStart();
if (Util.SDK_INT > 23) {
if (player == null) {
initializePlayer();
}
}
}
#Override
public void onResume() {
super.onResume();
if ((Util.SDK_INT <= 23 || player == null)) {
initializePlayer();
}
}
#Override
public void onPause() {
super.onPause();
if (Util.SDK_INT <= 23) {
releasePlayer();
}
}
#Override
public void onStop() {
super.onStop();
if (Util.SDK_INT > 23) {
releasePlayer();
}
}
private void releasePlayer() {
if (player != null) {
player.release();
player = null;
}
}
}
and the XML file to go with it.... The zoomable declaration is "on" right now but the code can easily use either the non-zoomable one or the PlayerView (by changing the type and not attaching the texture); that one works perfectly well, including properly handling rotation.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
<TextureView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/video_view3" />
<ua.polohalo.zoomabletextureview.ZoomableTextureView
android:id="#+id/video_view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
app:maxScale="4"/>
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/video_view"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:use_controller="false"/>
</FrameLayout>
Update: After much head-banging the following code works EXCEPT if you try to use it in a fragment, in which case the TextView extension has problems due to how minimum and maximum scale values get picked up. The obvious "hack" answer is to check for minScale = 0 and force it to 1.0 if you find it un-initialized.
Hope this helps someone else out.
package net.cudasystems.android.videotest;
import android.net.Uri;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.TextureView;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
public class MainActivity extends AppCompatActivity {
private String mURL = "http://set-to-an-mp4-URL"
TextureView mPlayerView;
SimpleExoPlayer player = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPlayerView = findViewById(R.id.video_view);
}
private void initializePlayer() {
DefaultRenderersFactory renderersFactory =
new DefaultRenderersFactory(this, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
player = ExoPlayerFactory.newSimpleInstance(
renderersFactory,
new DefaultTrackSelector(), new DefaultLoadControl());
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// Make sure the initial aspect ratio is 16:9 (otherwise a TextureView init's to the LARGER of
// the two dimensions of the video irrespective of the orientation setting and screws the aspect ratio!)
int width = metrics.widthPixels;
int newHeight = (width * 9) / 16;
mPlayerView.setLayoutParams(new ConstraintLayout.LayoutParams(width, newHeight));
mPlayerView.invalidate();
player.setVideoTextureView(mPlayerView);
player.setPlayWhenReady(true);
Uri uri = Uri.parse(mURL);
MediaSource mediaSource = buildMediaSource(uri);
player.prepare(mediaSource, true, true);
}
private MediaSource buildMediaSource(Uri uri) {
return new ExtractorMediaSource.Factory(
new DefaultHttpDataSourceFactory("exoplayer-codelab")).
createMediaSource(uri);
}
#Override
public void onStart() {
super.onStart();
if (Util.SDK_INT > 23) {
if (player == null) {
initializePlayer();
}
}
}
#Override
public void onResume() {
super.onResume();
if ((Util.SDK_INT <= 23 || player == null)) {
initializePlayer();
}
}
#Override
public void onPause() {
super.onPause();
if (Util.SDK_INT <= 23) {
releasePlayer();
}
}
#Override
public void onStop() {
super.onStop();
if (Util.SDK_INT > 23) {
releasePlayer();
}
}
private void releasePlayer() {
if (player != null) {
player.release();
player = null;
}
}
}
And the working XML to go with it:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:keepScreenOn="true">
<ua.polohalo.zoomabletextureview.ZoomableTextureView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
app:maxScale="4"
app:minScale="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Does This work?"
android:textColor="#android:color/holo_red_dark"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
I am trying to implement grid layout with image an text :
Each item have a text and an image and an action. This is how it should look:
layout grid
Use this as layout for your grid item.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
<TextView
android:id="#+id/picturetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_gravity="bottom"
android:textColor="#android:color/white"
android:background="#55000000"/>
This will give you result something like below.
Now to get the result as required in your sample you can change the width and height of alternate elements i.e modulo 2 elements. For even index items you can have square size dimensions and for odd index items you can have rectangular items.
Set the adapter for your gridView using this code.
GridView gridView = (GridView) view.findViewById(R.id.imagegridview);
gridView.setAdapter(new ImageAdapter(getActivity()));
Use this class as the image adapter.
public class ImageAdapter extends BaseAdapter {
private Context localContext;
private final LayoutInflater mInflater;
ImageAdapter(Context ct){
this.localContext = ct;
mInflater = LayoutInflater.from(localContext);
}
#Override
public int getCount() {
return imageTweets.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
ImageView picture;
TextView name;
if (convertView == null) {
v = mInflater.inflate(R.layout.new_grid_item, parent, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
v.setTag(R.id.picturetext, v.findViewById(R.id.picturetext));
} else
v = convertView;
picture = (ImageView) v.getTag(R.id.picture);
name = (TextView) v.getTag(R.id.picturetext);
picture.setImageUrl(imageTweets.get(position).entities.media.get(0).mediaUrl, mImageLoader);
name.setText(imageTweets.get(position).user.screenName);
return v;
}
}
In my case I am using url to load image therefore above code.
In your case you can directly set the image from resources. See if it works.
I've been trying to get a list view that can be swipe to change the its items to show the following or preceding week details. Here is what my layout file looks like
'
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/home_pannels_pager">
<ListView
android:id="#+id/week_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</android.support.v4.view.ViewPager>
But I didn't get what i want. Could you please help me? Thanks in advance.
This is not how ViewPager works. You feed the pages to ViewPager with a PagerAdapter. Your ListView will be contained within a Fragment created by the PagerAdapter.
In the layout:
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/home_pannels_pager" />
In the FragmentActivity with this layout:
ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
pager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
Example of simle PagerAdapter:
public class PagerAdapter extends FragmentPagerAdapter {
public FrontPageAdapter(FragmentManager Fm) {
super(Fm);
}
#Override
public Fragment getItem(int position) {
Bundle arguments = new Bundle();
arguments.putInt("position", position);
FragmentPage fragment = new FragmentPage();
fragment.setArguments(arguments);
return fragment;
}
#Override
public int getCount() {
// return count of pages
return 3;
}
}
Example of FragmentPage:
public class FragmentPage extends Fragment {
public FragmentPage() {}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_frontpage, container, false);
// probably cast to ViewGroup and find your ListView
Bundle arguments = getArguments();
int position = b.getInt("position");
return view;
}
}
I'm working with fragments (API 4.1) and I want to let the user press a button, access his/her gallery, select an image, and have that image display an imageview on the original fragment where the button appeared. I'm using the following code:
public class FillBox1Frag extends Fragment {
Button addPics, placeBox;
ImageView imgView;
Bitmap b;
Uri photoUri;
LinearLayout fillBoxLayout;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
if (container == null) {
return null;
}
fillBoxLayout = (LinearLayout) inflater.inflate(R.layout.fillbox1_frag,
container, false);
newBin = new Bin();
addPics = (Button) fillBoxLayout.findViewById(R.id.bPics);
imgView = (ImageView) fillBoxLayout.findViewById(R.id.imageView1);
addPics.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent picChooser = new Intent(Intent.ACTION_GET_CONTENT,
MediaStore.Images.Media.INTERNAL_CONTENT_URI);
picChooser.setType("image/*");
startActivityForResult(picChooser, 12345);
}
});
return fillBoxLayout;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 12345:
if (resultCode == 12345) {
photoUri = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = FillBox1Frag.this.getActivity()
.getContentResolver()
.query(photoUri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
b = BitmapFactory.decodeFile(filePath);
imgView.setImageBitmap(b);
}
}
}
I access the Gallery, but upon selection, it just returns to the original fragment and doesn't display the image. Here's my XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fillbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="fillbox" >
<Button
android:id="#+id/bPics"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="89dp"
android:background="#drawable/buttonpics" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
I've found plenty of answers dealing with a similar question, but nothing that has been able to help me with how to create this process using fragments. Any ideas on how to get my selected image to appear in the ImageView? Thanks for the help!