Example usage for android.widget ArrayAdapter setNotifyOnChange

List of usage examples for android.widget ArrayAdapter setNotifyOnChange

Introduction

In this page you can find the example usage for android.widget ArrayAdapter setNotifyOnChange.

Prototype

public void setNotifyOnChange(boolean notifyOnChange) 

Source Link

Document

Control whether methods that change the list ( #add , #addAll(Collection) , #addAll(Object[]) , #insert , #remove , #clear , #sort(Comparator) ) automatically call #notifyDataSetChanged .

Usage

From source file:org.solovyev.android.calculator.history.AbstractCalculatorHistoryFragment.java

private void updateAdapter() {
    final List<CalculatorHistoryState> historyList = getHistoryList();

    final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
    try {//from w  ww  .  j  a va  2  s  .  c  o m
        adapter.setNotifyOnChange(false);
        adapter.clear();
        for (CalculatorHistoryState historyState : historyList) {
            adapter.add(historyState);
        }
    } finally {
        adapter.setNotifyOnChange(true);
    }

    adapter.notifyDataSetChanged();
}

From source file:com.xperia64.timidityae.TrackFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    reset();//from  www .  ja v a2 s  . c o  m

    fileList = new ArrayAdapter<String>(getActivity(), R.layout.row);
    for (int i = 0; i < JNIHandler.MAX_CHANNELS; i++) {
        fileList.add(String.format(getActivity().getResources().getString(R.string.trk_form),
                (getActivity().getResources()
                        .getString(JNIHandler.drums.get(i) ? R.string.trk_drum : R.string.trk_inst2)),
                (i + 1), JNIHandler.drums.get(i) ? 0 : localInst.get(i) + 1, localVol.get(i)));
    }
    channelList.setAdapter(fileList);
    channelList.setOnItemClickListener(new OnItemClickListener() {

        @SuppressLint("InflateParams")
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
            AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
            View v = getActivity().getLayoutInflater().inflate(R.layout.track_dialog, null);
            final Spinner instSpin = (Spinner) v.findViewById(R.id.instSpin);
            instSpin.setClickable(JNIHandler.custInst.get(arg2) && !JNIHandler.drums.get(arg2));
            instSpin.setOnLongClickListener(null);
            instSpin.setEnabled(JNIHandler.custInst.get(arg2) && !JNIHandler.drums.get(arg2));
            List<String> arrayAdapter = new ArrayList<String>();
            final int offset = (!JNIHandler.drums.get(arg2)) ? 0 : 34;
            if (!JNIHandler.drums.get(arg2)) {
                for (String inst : getActivity().getResources().getStringArray(R.array.midi_instruments))
                    arrayAdapter.add(inst);
            } else {
                for (String inst : getActivity().getResources().getStringArray(R.array.midi_drums))
                    arrayAdapter.add(inst);
            }
            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item, arrayAdapter);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
            } else {
                dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            }

            dataAdapter.setNotifyOnChange(false);
            if (!JNIHandler.drums.get(arg2)) {
                instSpin.setAdapter(dataAdapter);
                instSpin.setSelection(localInst.get(arg2) - offset);
            }
            final EditText txtVol = (EditText) v.findViewById(R.id.txtVol);
            txtVol.setText(Integer.toString(localVol.get(arg2)));
            txtVol.setClickable(JNIHandler.custVol.get(arg2));
            txtVol.setEnabled(JNIHandler.custVol.get(arg2));

            final SeekBar volSeek = (SeekBar) v.findViewById(R.id.volSeek);
            volSeek.setClickable(JNIHandler.custVol.get(arg2));
            volSeek.setEnabled(JNIHandler.custVol.get(arg2));
            volSeek.setMax(127);
            volSeek.setProgress(localVol.get(arg2));
            volSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
                    if (arg2 && !fromUser) {
                        fromUser = true;
                        txtVol.setText(Integer.toString(arg0.getProgress()));
                    } else {
                        fromUser = false;
                    }
                }

                @Override
                public void onStartTrackingTouch(SeekBar arg0) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar arg0) {
                }

            });

            txtVol.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    if (!fromUser) {
                        if (s.length() > 0) {
                            int numm = Integer.parseInt(s.toString());
                            if (numm > 127) {
                                fromUser = true;
                                numm = 127;
                            }
                            if (numm < 0) {
                                fromUser = true;
                                numm = 0;
                            }
                            if (fromUser) {
                                txtVol.setText(Integer.toString(numm));
                            }
                            fromUser = true;
                            volSeek.setProgress(numm);
                            fromUser = false;
                        }
                    } else {
                        fromUser = false;
                    }
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });
            final CheckBox inst = (CheckBox) v.findViewById(R.id.defInstr);
            inst.setEnabled(!JNIHandler.drums.get(arg2));
            inst.setChecked(!JNIHandler.custInst.get(arg2));
            inst.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

                    instSpin.setClickable(!arg1);
                    instSpin.setEnabled(!arg1);
                }

            });
            final CheckBox vol = (CheckBox) v.findViewById(R.id.defVol);
            vol.setChecked(!JNIHandler.custVol.get(arg2));
            //System.out.println("Def inst: "+(!JNIHandler.custInst.get(arg2)?"true":"false")+" def vol: "+(!JNIHandler.custVol.get(arg2)?"true":"false"));
            vol.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

                    volSeek.setClickable(!arg1);
                    volSeek.setEnabled(!arg1);
                    txtVol.setClickable(!arg1);
                    txtVol.setEnabled(!arg1);
                }

            });
            if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                v.setBackgroundColor(Globals.theme == 1 ? Color.WHITE : Color.BLACK);
            b.setView(v);
            b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    JNIHandler.custInst.set(arg2, !inst.isChecked());
                    JNIHandler.custVol.set(arg2, !vol.isChecked());
                    JNIHandler.setChannelVolumeTimidity(arg2 | (JNIHandler.custVol.get(arg2) ? 0x800 : 0x8000),
                            volSeek.getProgress());
                    JNIHandler.setChannelTimidity(arg2 | (JNIHandler.custInst.get(arg2) ? 0x800 : 0x8000),
                            instSpin.getSelectedItemPosition());
                    if (!JNIHandler.paused && Globals.isPlaying == 0)
                        JNIHandler.seekTo(JNIHandler.currTime);
                    //bigCounter=12;
                    updateList();
                }
            });

            b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            b.setTitle(String.format((getActivity().getResources().getString(R.string.trk_form2)), (arg2 + 1)));
            ddd = b.create();
            ddd.show();
        }

    });
}

From source file:org.uguess.android.sysinfo.NetStateManager.java

void refresh() {
    ArrayList<ConnectionItem> data = new ArrayList<ConnectionItem>();

    data.add(dummyInfo);//from  w w w  . j  a  v  a 2s .c  om

    ArrayList<ConnectionItem> items = readStatesRaw();

    if (items != null) {
        final int type = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_ORDER_TYPE,
                ORDER_TYPE_PROTO);
        final int direction = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_DIRECTION,
                ORDER_ASC);
        final Collator clt = Collator.getInstance();

        switch (type) {
        case ORDER_TYPE_PROTO:
            Collections.sort(items, new Comparator<ConnectionItem>() {

                public int compare(ConnectionItem obj1, ConnectionItem obj2) {
                    return clt.compare(obj1.proto, obj2.proto) * direction;
                }
            });
            break;
        case ORDER_TYPE_LOCAL:
            Collections.sort(items, new Comparator<ConnectionItem>() {

                public int compare(ConnectionItem obj1, ConnectionItem obj2) {
                    return clt.compare(obj1.local, obj2.local) * direction;
                }
            });
            break;
        case ORDER_TYPE_REMOTE:
            Collections.sort(items, new Comparator<ConnectionItem>() {

                public int compare(ConnectionItem obj1, ConnectionItem obj2) {
                    return clt.compare(obj1.remoteName == null ? obj1.remote : obj1.remoteName,
                            obj2.remoteName == null ? obj2.remote : obj2.remoteName) * direction;
                }
            });
            break;
        case ORDER_TYPE_STATE:
            Collections.sort(items, new Comparator<ConnectionItem>() {

                public int compare(ConnectionItem obj1, ConnectionItem obj2) {
                    return clt.compare(obj1.state == null ? "" //$NON-NLS-1$
                            : obj1.state,
                            obj2.state == null ? "" //$NON-NLS-1$
                                    : obj2.state)
                            * direction;
                }
            });
            break;
        }

        data.addAll(items);
    }

    ArrayAdapter<ConnectionItem> adapter = (ArrayAdapter<ConnectionItem>) getListView().getAdapter();

    adapter.setNotifyOnChange(false);

    adapter.clear();

    for (int i = 0, size = data.size(); i < size; i++) {
        adapter.add(data.get(i));
    }

    adapter.notifyDataSetChanged();

    if (adapter.getCount() == 1) {
        Log.d(NetStateManager.class.getName(), "No network traffic detected"); //$NON-NLS-1$
    }
}

From source file:org.uguess.android.sysinfo.SiragonManager.java

void refresh() {
    ArrayAdapter<PrefItem> adapter = (ArrayAdapter<PrefItem>) getListAdapter();

    adapter.setNotifyOnChange(false);
    adapter.clear();//w  w  w  .j  ava 2s.c o m

    for (Entry<String, PrefItem> ent : prefs.entrySet()) {
        adapter.add(ent.getValue());
    }

    adapter.notifyDataSetChanged();
}