Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Wallpaper from gallery according to position
    primarykey
    data
    text
    <p>I have a Gallery and an imageView as in this pic: <a href="http://i50.tinypic.com/2e6h2so.png" rel="nofollow">http://i50.tinypic.com/2e6h2so.png</a> and i need button1 to set the current image as wallpaper I am having a problem in setResource</p> <pre><code> myWallpaperManager.setResource(mImageIds[position]); </code></pre> <p>This is my code:</p> <pre><code> public class batman extends Activity implements OnClickListener{ Button set; private int[] mImageIds = { R.drawable.b, R.drawable.b1, R.drawable.b2, R.drawable.b3, R.drawable.b4, R.drawable.b5, R.drawable.b6, R.drawable.b7, R.drawable.b8, R.drawable.b9, R.drawable.b10, R.drawable.b11, R.drawable.b12, R.drawable.b13, R.drawable.b14, R.drawable.b15, R.drawable.b16, R.drawable.b17, R.drawable.b18, R.drawable.b19, R.drawable.b20, R.drawable.b21, R.drawable.b22, R.drawable.b23, R.drawable.b24, }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.batman); set=(Button)findViewById(R.id.button1); set.setOnClickListener(this); Gallery g = (Gallery) findViewById(R.id.gallery); g.setAdapter(new ImageAdapter(this)); g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick (AdapterView&lt;?&gt; parent, View v, int position, long id) { ImageView imageView =(ImageView)findViewById(R.id.imageView1); imageView.setImageResource(mImageIds[position]); } }); } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; public ImageAdapter(Context c) { mContext = c; TypedArray a = c.obtainStyledAttributes(R.styleable.GalleryA); mGalleryItemBackground = a.getResourceId( R.styleable.GalleryA_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setLayoutParams(new Gallery.LayoutParams(150, 100)); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setBackgroundResource(mGalleryItemBackground); return i; } } public void onClick(View arg0) { // TODO Auto-generated method stub int id=arg0.getId(); if(id==R.id.button1) { WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext()); try { myWallpaperManager.setResource(mImageIds[position]); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } </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.
    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