Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>do you have @Override above your onActivityRestult?</p> <p>(looking at old code that does this so not sure why its needed) call super.onactivityresult(requestcode, resultscode, data) as the first call in the method</p> <p>also my intents didnt have that other stuff in them startActivityForResult(Intent.createChooser(intent, "Select Picture"), 0); i think should just be startActivityForResult(source.class, destination.class); of course source and destination should be the name of the classes</p> <pre><code>public class ImageSwitcherView extends Activity { int pics[] = { R.drawable.image000, R.drawable.image001, R.drawable.image002}; private int currentIndex = 0; SharedPreferences preferences; Gallery gallery; ImageView fullPicView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.galleryview); Bundle extras = getIntent().getExtras(); currentIndex = extras.getInt("bookmark"); gallery = (Gallery) findViewById(R.id.Gallery01); gallery.setAdapter(new ImageAdapter(this)); gallery.setSelection(currentIndex); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { currentIndex = position; // ---display the images selected--- fullPicView = (ImageView) findViewById(R.id.imageView1); fullPicView.setImageResource(pics[currentIndex]); fullPicView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent myIntent = new Intent(ImageSwitcherView.this, imageView.class); int resID = pics[currentIndex]; myIntent.putExtra("resID", resID); myIntent.putExtra("index", currentIndex); startActivityForResult(myIntent, 1); } }); } }); } public class ImageAdapter extends BaseAdapter { private Context context; private int itemBackground; public ImageAdapter(Context c) { context = c; // ---setting the style--- TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); itemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } // ---returns the number of images--- public int getCount() { return pics.length; } // ---returns the ID of an item--- public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } // ---returns an ImageView view--- public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView = new ImageView(context); imageView.setImageResource(pics[position]); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setLayoutParams(new Gallery.LayoutParams(150, 120)); imageView.setBackgroundResource(itemBackground); return imageView; } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); currentIndex = data.getIntExtra("bookmark", 0); gallery.setSelection(currentIndex); fullPicView.setImageResource(pics[currentIndex]); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) { preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("bookmark", gallery.getSelectedItemPosition()); editor.commit(); finish(); } return super.onKeyDown(keyCode, event); } } </code></pre>
    singulars
    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