Problem in onItemSelected

Put your problem here if it does not fit any of the other categories.

Problem in onItemSelected

Postby soniya » Mon Jan 28, 2008 1:35 pm

in A android.widget.Gallery - Example

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class GalleryExample extends Activity AdapterView.OnItemSelectedListener{
  2.  
  3. ImageView i;
  4.  
  5.     /** Called when the activity is first created. */
  6.  
  7.     @Override
  8.  
  9.     public void onCreate(Bundle icicle) {
  10.  
  11.         super.onCreate(icicle);
  12.  
  13.         setContentView(R.layout.main);
  14.  
  15.  
  16.  
  17.         /* Find the gallery defined in the main.xml
  18.  
  19.          * Apply a new (custom) ImageAdapter to it. */
  20.  
  21.   Gallery g = (Gallery) findViewById(R.id.image1);
  22.  
  23.                       g.setAdapter(new ImageAdapter(this));
  24.  
  25.  
  26.  
  27.  g.setOnItemSelectedListener(this);
  28.  
  29.     }
  30.  
  31.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


and in getView method


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public View getView(int position, View convertView, ViewGroup parent) {
  2.  
  3.             ImageView i = new ImageView(this.myContext);
  4.  
  5.  
  6.  
  7.             i.setImageResource(this.myImageIds[position]);
  8.  
  9.             /* Image should be scaled as width/height are set. */
  10.  
  11.             i.setScaleType(ImageView.ScaleType.FIT_XY);
  12.  
  13.             /* Set the Width/Height of the ImageView. */
  14.  
  15.             i.setLayoutParams(new Gallery.LayoutParams(150, 150));
  16.  
  17.               i.setBackground(android.R.drawable.picture_frame);
  18.  
  19.             return i;
  20.  
  21.         }
  22.  
  23.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


i want change background of selected image in onItemSelected method

i used

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onItemSelected(AdapterView parent, View v, int position, long id) {
  2.  
  3.          i.setBackground(android.R.drawable.panel_picture_frame_bg_pressed_blue  );
  4.  
  5.           invalidate();
  6.  
  7. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


but don't change selected image background,change last two images background......how to change selected image background??
soniya
Senior Developer
Senior Developer
 
Posts: 111
Joined: Mon Jan 14, 2008 1:52 pm
Location: india

Top

Postby soniya » Tue Jan 29, 2008 1:12 pm

:roll:

i want change selected image background in OnitemSelected mehod...
soniya
Senior Developer
Senior Developer
 
Posts: 111
Joined: Mon Jan 14, 2008 1:52 pm
Location: india

Postby rmeph » Wed Jan 30, 2008 12:41 pm

u use in onItemSelected method

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. v.setBackground(android.R.drawable.panel_picture_frame_bg_pressed_blue);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



may be it's work........
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Postby soniya » Wed Jan 30, 2008 1:03 pm

thanks for reply.....actually i used two image in getview

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public View getView(int position, View convertView, ViewGroup parent) {
  2.  
  3.                         // TODO Auto-generated method stub
  4.  
  5.                
  6.  
  7.                         RelativeLayout ll = new RelativeLayout(mContext);
  8.  
  9.                         i = new ImageView(mContext);
  10.  
  11.                 i.setImageResource(this.myImageIds[position]);
  12.  
  13.                     RelativeLayout.LayoutParams p1 = new RelativeLayout.LayoutParams(100,100);
  14.  
  15.             p1.setMargins(15, 0, 0, 0);
  16.  
  17.                 ll.addView(i,p1);
  18.  
  19.                      ImageView i1 = new ImageView(mContext);
  20.  
  21.               i1.setImageResource(this.myImageIds[position]);
  22.  
  23.               RelativeLayout.LayoutParams p2 = new RelativeLayout.LayoutParams(
  24.  
  25.                   25,25);
  26.  
  27.           p2.setMargins(100, 200, 0, 0);
  28.  
  29.            ll.addView(i1,p2);
  30.  
  31.  return ll;
  32.  
  33.                 }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


when i used v.setbackground in itemselected method then it set background in both image i want set background only one image and only selected image....
soniya
Senior Developer
Senior Developer
 
Posts: 111
Joined: Mon Jan 14, 2008 1:52 pm
Location: india

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests