انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
مشکل در Shared Preferences (ذخیره تصویر پس زمینه layout) (برنامه نویسی اندروید)

مشکل در Shared Preferences (ذخیره تصویر پس زمینه layout) (برنامه نویسی اندروید)

#1
سلام 
یه مشکلی با این برنامه پیدا کردم
میخوام وقتی یه تصویری رو از گالری میگیرم بندازمش بکگراند یه لینیر لایوت
خوب تا اینجاش که هیچی
ولی وقتی میخوام اینو ذخیره کنم که دفعه بعدم که میام همون تصویره همچنان بکگراند بمونه
بر میگرده همون پیش فرض
یه نکته ایم بگم که صفحه تنظیمات برنامم هست و اطلاعات رو به صفحات دیگه میفرستم یعنی باید توی اکتیویتی های دیگه از این تصویر بعنوان بکگراند لینیر لایوتم استفا ده کنم

اینم کدش

کد:
Integer[] imageIDs = {
           R.drawable.background2,
           R.drawable.img_bdeff,
           R.drawable.imgb_9nomreie,
           R.drawable.imgb_5dolar,
           R.drawable.imgb_andaki_sabr,
           R.drawable.imgb_chomanaiamouravad,
           R.drawable.imgb_emamreza
   };

SharedPreferences shFont , shBack ;
LinearLayout sasa;
int position;


protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_new_sett);

sasa = (LinearLayout) findViewById(R.id.myLinearLayout);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
       gallery.setAdapter(new ImageAdapter(this));
       gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
           public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
               // display the images selected
               sasa.setBackgroundResource(imageIDs[position]);
               //imageView.setImageResource(imageIDs[position]);
           }
       });

shBack = getSharedPreferences("settingBack", 0);
       position = shBack.getInt("back?", 0);// pishfars background aval

sasa.setBackgroundResource(imageIDs[position]);


public class cOnItemSelectedListener implements OnItemSelectedListener {

       @Override
       public void onItemSelected(AdapterView<?> parent, View arg1, int post,
                                  long id) {
           
           sasa.setBackgroundResource(imageIDs[position]);

       }

@Override
       public void onNothingSelected(AdapterView<?> arg0) {
           // TODO Auto-generated method stub

       }

   }
   @Override
   protected void onPause() {
       // TODO Auto-generated method stub
       super.onPause();
    SharedPreferences.Editor ed2 = shBack.edit();
       ed2.putInt("back?", position);
       ed2.commit();
       sasa.setBackgroundResource(imageIDs[position]);
   }
public class ImageAdapter extends BaseAdapter {
       private Context context;
       private int itemBackground;
       public ImageAdapter(Context c)
       {
           context = c;
           // sets a grey background; wraps around the images
           TypedArray a =obtainStyledAttributes(R.styleable.MyGallery);
           itemBackground = a.getResourceId(R.styleable.MyGallery_android_galleryItemBackground, 0);
           a.recycle();
       }
       // returns the number of images
       public int getCount() {
           return imageIDs.length;
       }
       // returns the ID of an item
       public Object getItem(int position) {
           return position;
       }
       // returns the ID of an item
       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(imageIDs[position]);
           imageView.setLayoutParams(new Gallery.LayoutParams(100, 100));
           imageView.setBackgroundResource(itemBackground);
           return imageView;
       }

   }


}
پاسخ


پیام‌های این موضوع
مشکل در Shared Preferences (ذخیره تصویر پس زمینه layout) (برنامه نویسی اندروید) - توسط ze_ca - ۱۳۹۴/۱۱/۱۷, ۱۲:۰۱ ب.ظ
RE: مشکل در Shared Preferences - توسط دیب دمینی - ۱۳۹۴/۱۱/۱۸, ۰۲:۴۴ ق.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان