title: Receive ArrayList from Custom Adapter
body: <p>Ive got a Array List in my CustomAdapter filled with the id of my checked element.</p>
  
  <pre><code> elementChecker.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (elementChecker.isChecked()) {
                  checkedElements.add(id);
              } else {
                  for (int i = 0; i &lt; checkedElements.size() ; i++){
                      checkedElements.remove(id);
                  }
              }
          }
      });
  </code></pre>
  
  <p>But how do I get access to this list from my Fragment?Thanks for your help.</p>
  
  <p>EDIT: This is my getter But I cant call it from my Fragment.</p>
  
  <pre><code>    public List&lt;String&gt; getSelectedElements(){
      return checkedElements;
  }
  </code></pre>
  
  <p>The Adapter is set in my DataListFragment:</p>
  
  <pre><code>    final ListAdapter dataListAdapter = new CustomListAdapter(context, dataListArray);
          final ListView dataListListView = (ListView) view.findViewById(R.id.listView_datalist);
  
          dataListListView.setAdapter(dataListAdapter);
  </code></pre>
  
  <p>EDIT2: Added The Fragment Code</p>
  
  <pre><code>public class ListViewFragment extends Fragment {
  
      DbHelper mydb;
      Spinner locationpicker;
  
      LinearLayout qrStickerLayout;
      ImageView qrCodeSticker;
      TextView labelSticker;
      TextView serialSticker;
  
  
      private EditText roomnr;
  
      public boolean roomNrOk = false;
      public boolean locationOk = false;
      public boolean listViewOk = false;
  
      String actualLocation;
      String dataList = "";
      String selectedFromList;
      String[] selectedElementArray;
  
  
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_listview, container, false);
  
          getActivity().setTitle(getString(R.string.listView));
  
          registerForContextMenu(view);
  
          final Context context = getContext();
          mydb = new DbHelper(context);
          locationpicker = (Spinner) view.findViewById(R.id.spinner_locations);
          roomnr = (EditText) view.findViewById(R.id.editText_roomNr);
  
          qrCodeSticker = (ImageView) view.findViewById(R.id.imageView_qrcode);
          labelSticker = (TextView) view.findViewById(R.id.textView_QrSticker_label);
          serialSticker = (TextView) view.findViewById(R.id.textView_QrSticker_serial);
          qrStickerLayout = (LinearLayout) view.findViewById(R.id.linearLayout_QrCode);
  
  
          Drawable drawableForFabSave = getResources().getDrawable(R.drawable.ic_save);
          ((MainActivity) getActivity()).fabsave.setImageDrawable(drawableForFabSave);
  
          Drawable drawableForFabAdd = getResources().getDrawable(R.drawable.ic_add);
          ((MainActivity) getActivity()).fabmain.setImageDrawable(drawableForFabAdd);
          ((MainActivity) getActivity()).fabmain.animate().translationY(0);
          ((MainActivity) getActivity()).fabmain.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  ((MainActivity) getActivity()).scanQRCode();
                  ((MainActivity) getActivity()).loadListViewFragment();
              }
          });
  
          ((MainActivity) getActivity()).fabdelete.animate().translationY(0);
  
          final String locationNamesFromTableArray = mydb.getLocationNames();
  
          if(!locationNamesFromTableArray.isEmpty()){
              String[] roomNumbersFromTableArrayFinal = locationNamesFromTableArray.split("\t");
              ArrayAdapter&lt;String&gt; adapter_locations;
              adapter_locations = new ArrayAdapter&lt;&gt;(context, android.R.layout.simple_spinner_dropdown_item, roomNumbersFromTableArrayFinal);
              locationpicker.setAdapter(adapter_locations);
  
              setFabdeleteVisible(listViewOk);
          }
  
          locationpicker.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  actualLocation = locationpicker.getSelectedItem().toString();
                  locationOk = true;
                  setFabsVisible(roomNrOk, true, listViewOk);
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
              }
          });
  
          roomnr.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {}
  
              @Override
              public void afterTextChanged(Editable s) {
                  Pattern p = Pattern.compile("^[0-9]{3}$");
                  Matcher m = p.matcher(s);
  
                  roomNrOk = m.find();
                  setFabsVisible(roomNrOk, locationOk, listViewOk);
              }
          });
  
          dataList = mydb.getElementsWithoutRoom();
  
  
          if (!dataList.isEmpty()) {
              final String[] dataListArray = dataList.split("\n");
  
              final ListAdapter dataListAdapter = new CustomListAdapter(context, dataListArray);
              final ListView dataListListView = (ListView) view.findViewById(R.id.listView_datalist);
  
              dataListListView.setAdapter(dataListAdapter);
  
              dataListListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                      selectedFromList = (dataListListView.getItemAtPosition(position).toString());
                      selectedElementArray = selectedFromList.split("\t");
                      dataListListView.showContextMenu();
                  }
  
              });
  
              ((MainActivity) getActivity()).fabdelete.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      mydb.deleteAllWithoutRoom();
                      listViewOk = false;
                      dataListListView.setAdapter(dataListAdapter);
  
                      Toast toast = Toast.makeText(context, getResources().getString(R.string.toast_deleted), Toast.LENGTH_SHORT);
                      toast.show();
  
                      reloadListViewFragment();
                  }
              });
  
          }else{
              TextView emptyElement = (TextView) view.findViewById(R.id.emptyElement);
              emptyElement.setVisibility(View.VISIBLE);
          }
  
          ((MainActivity) getActivity()).fabsave.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (roomNrOk &amp;&amp; locationOk &amp;&amp; !dataList.isEmpty()) {
                      String successfullSaved = getResources().getString(R.string.successfully)+ actualLocation + "-" + roomnr.getText().toString() + getResources().getString(R.string.saved);
  
                      mydb.setRoomNr(roomnr.getText().toString());
                      mydb.setRoomId(roomnr.getText().toString());
  
                      mydb.setLocationId(actualLocation);
  
                      Toast toast = Toast.makeText(getActivity(), successfullSaved, Toast.LENGTH_SHORT);
                      toast.show();
  
                      reloadListViewFragment();
                  } else {
                      Toast toast = Toast.makeText(getActivity(), getString(R.string.error_listView), Toast.LENGTH_SHORT);
                      toast.show();
                  }
              }
          });
  
          ((MainActivity) getActivity()).fabexport.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  try {
                      File myDir = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + getResources().getString(R.string.sdcard_path));
                      if (!myDir.exists()) {
                          myDir.mkdir();
                      }
                      String fileName = getResources().getString(R.string.roomname) + actualLocation + getResources().getString(R.string.underline) + roomnr.getText().toString() + getResources().getString(R.string.roomname_ending);
                      File file = new File(myDir, fileName);
                      file.createNewFile();
  
                      FileOutputStream fOut = new FileOutputStream(file);
                      OutputStreamWriter fos = new OutputStreamWriter(fOut);
                      fos.write(dataList);
                      fos.close();
                      fOut.close();
  
                      Toast toast = Toast.makeText(getActivity(), fileName + getResources().getString(R.string.saved), Toast.LENGTH_SHORT);
                      toast.show();
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
  
  
          return view;
      }
  
      public void reloadListViewFragment(){
          Fragment fragment;
          FragmentTransaction ft = getFragmentManager().beginTransaction();
          fragment = new ListViewFragment();
          ft.replace(R.id.container, fragment);
          ft.commitAllowingStateLoss();
      }
  
  }
  </code></pre>