title: How to pass the SharedPreferences data from the settingActivity to the MainAdapter?
body: <p>I created a shopping cart app, and it has a menu item. Then it has another activity called "SettingActivity", for this settingActivity will have a TextView to show "Primary language, secondary language and both language". </p>
  
  <p>I got the SharedPreferences data in the SettingActivity. How can I pass those data to the MainAdapter?</p>
  
  <p>Because when I click the secondary language in the SettingActivity, then the menu will change to secondary language or show both languages.</p>
  
  <p>So, how can I get the SettingActivity's SharedPreference data in the MainAdapter?</p>
  
  <p>SettingActivity:</p>
  
  <pre><code>public class SettingActivity extends AppCompatActivity {
  LinearLayout languageModeLinearLayout;
  TextView languageModeTextView;
  SharedPreferences settingPreferences;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_setting);
      languageModeLinearLayout = findViewById(R.id.setting_language_mode_linearLayout);
      languageModeTextView = findViewById(R.id.setting_language_mode_textView);
      settingPreferences = getSharedPreferences("setting", MODE_PRIVATE);
  
      updateUI();
  
      languageModeLinearLayout.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              final String[] language = getResources().getStringArray(R.array.setting_language_mode);
              AlertDialog.Builder languageMode = new AlertDialog.Builder(v.getContext());
              languageMode.setTitle("Select Language Mode");
             languageMode.setItems(language, new DialogInterface.OnClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int position) {
                     SharedPreferences.Editor editor = settingPreferences.edit();
                     editor.putInt("language", position);
                     editor.apply();
                     updateUI();
                 }
             });
  
             languageMode.create().show();
          }
      });
  
  
  }
  
  private String getLanguage(){
      String[] language = getResources().getStringArray(R.array.setting_language_mode);
      int position;
   position  = settingPreferences.getInt("language", 0);
  
   return language[position];
  }
  
  private void updateUI(){
      languageModeTextView.setText(getLanguage());
  }
  </code></pre>
  
  <p>MainAdapter:</p>
  
  <pre><code>public class MainAdapter extends ArrayAdapter&lt;MenuItem&gt; implements Serializable {
  private TextView mCartCounterTextView;
  
  public MainAdapter(Context context, List&lt;MenuItem&gt; menuItems) {
      super(context, 0, menuItems);
  }
  
  @NonNull
  @Override
  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
      View itemView = convertView;
      final ViewHolder viewHolder;
  
      if (itemView == null) {
          itemView = LayoutInflater.from(getContext()).inflate(R.layout.item_main, parent, false);
          viewHolder = new ViewHolder(itemView);
          itemView.setTag(viewHolder);
      } else {
          viewHolder = (ViewHolder) itemView.getTag();
      }
  
      final MenuItem currentMenuItem = getItem(position);
      viewHolder.nameTextView.setText(currentMenuItem.getPrimaryName());
      viewHolder.nameTextView.setText(currentMenuItem.getSecondaryName());
  
      viewHolder.addToCartButton.setText(getFormattedPriceTextToButton(currentMenuItem));
      viewHolder.addToCartButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Main.getAddedItems().add(currentMenuItem);
              Toast.makeText(v.getContext(), "Item had added to cart", Toast.LENGTH_SHORT).show();
  
              mCartCounterTextView.setText(String.valueOf(Main.getAddedItems().size()));
              mCartCounterTextView.setVisibility(View.VISIBLE);
          }
      });
      return itemView;
  }
  
  private String getFormattedPriceTextToButton(MenuItem currentMenuItem) {
      return "+ $" + currentMenuItem.getPrice();
  }
  
  private class ViewHolder {
      TextView nameTextView;
      TextView priceTextView;
      Button addToCartButton;
  
      public ViewHolder(View itemView) {
          nameTextView = itemView.findViewById(R.id.main_name_textView);
          priceTextView = itemView.findViewById(R.id.main_price_textView);
          addToCartButton = itemView.findViewById(R.id.main_add_to_cart_button);
      }
  }
  
  public void setData(TextView cartCounter){
      mCartCounterTextView = cartCounter;
  }
  
  private void getSharedPreferencesLanguage(){
    //  SharedPreferences.Editor editor = getContext().getSharedPreferences("setting", MODE_PRIVATE).edit();
      SharedPreferences language = getContext().getSharedPreferences("setting", MODE_PRIVATE);
  }
  </code></pre>
  
  <p>MenuItem:</p>
  
  <pre><code>public class MenuItem {
  private String mPrimaryName;
  private String mSecondaryName;
  private double mPrice;
  
  public MenuItem(String primaryName, String secondaryName, double price){
      mPrimaryName = primaryName;
      mSecondaryName = secondaryName;
      mPrice = price;
  }
  
  public String getPrimaryName(){
      return mPrimaryName;
  }
  public String getSecondaryName(){
      return mSecondaryName;
  }
  public double getPrice(){
      return mPrice;
  }
  </code></pre>