0

这可能是一个愚蠢的问题,因为我是新手,但是无论如何创建一个类来存储不是用户的共享首选项而是共享首选项的结果?因为我有一个主屏幕,它可能会根据用户输入生成数百个动态 ImageButton(显然一次不超过六个左右)。

到目前为止,我将它放在我的主屏幕代码中,它工作正常,但对于所有不同的可能输入,它似乎并不可行/不可能。

ImageButton ab = new ImageButton(this);
ImageButton ca = new ImageButton(this);

ca.setId(R.id.ca);
ab.setId(R.id.ab);
SharedPreferences caprefs = PreferenceManager.getDefaultSharedPreferences(this);{
LinearLayout     ll = (LinearLayout)findViewById(R.id.sundayboxopen

);

       if(caprefs.getBoolean("cacheckBoxon", true)) {    
       ll.addView(ca);
       ca.setImageResource(R.drawable.cobutton1);

       ca.setBackgroundColor(View.GONE);
       }else{
       if(caprefs.getBoolean("cacheckBoxoff", true)){

       ll.addView(ca);
       ca.setVisibility(View.GONE);}

       }}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);{

    LinearLayout     ll = (LinearLayout)findViewById(R.id.sundayboxopen);

    if(prefs.getBoolean("checkBoxon", true)) {
    ll.addView(ab);
    ab.setImageResource(R.drawable.adaba);

    ab.setBackgroundColor(View.GONE);

    }else{
if(prefs.getBoolean("checkBoxoff", true)){


    ll.addView(ab);
  ab.setVisibility(View.GONE);}

    }}

正如您所看到的那样,那里只有两个按钮caab如果我可以将这些进程单独存储在一个或几个专用类中,那就太好了,当我启动/重新启动应用程序时,这些类在“幕后”被选中。提前致谢

4

0 回答 0