Java Code Examples for android.widget.ArrayAdapter#notifyDataSetChanged()

The following examples show how to use android.widget.ArrayAdapter#notifyDataSetChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubPoiSearchActivity.java    From TraceByAmap with MIT License 6 votes vote down vote up
@Override
  public void onGetInputtips(List<Tip> tipList, int rCode) {
      if (rCode == AMapException.CODE_AMAP_SUCCESS) {
          if (tipList != null) {
              List<String> listString = new ArrayList<String>();
              int size = tipList.size();
              for (int i = 0; i < size; i++) {
                  listString.add(tipList.get(i).getName());
              }
              ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(
                      getApplicationContext(),
                      R.layout.route_inputs, listString);
              mKeywordText.setAdapter(aAdapter);
              aAdapter.notifyDataSetChanged();
          }
      } else {
      	ToastUtil.showerror(this, rCode);
}     
  }
 
Example 2
Source File: PoiKeywordSearchActivity.java    From TraceByAmap with MIT License 6 votes vote down vote up
@Override
public void onGetInputtips(List<Tip> tipList, int rCode) {
	if (rCode == AMapException.CODE_AMAP_SUCCESS) {// 正确返回
		List<String> listString = new ArrayList<String>();
		for (int i = 0; i < tipList.size(); i++) {
			listString.add(tipList.get(i).getName());
		}
		ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(
				getApplicationContext(),
				R.layout.route_inputs, listString);
		searchText.setAdapter(aAdapter);
		aAdapter.notifyDataSetChanged();
	} else {
		ToastUtil.showerror(this, rCode);
	}
	
}
 
Example 3
Source File: MainActivity.java    From a-sync-browser with Mozilla Public License 2.0 6 votes vote down vote up
private void updateSearchResultListView(){
    ListView listView = (ListView) findViewById(R.id.main_search_results_list_view);
    ArrayAdapter<FileInfo> arrayAdapter=((ArrayAdapter)listView.getAdapter());
    arrayAdapter.clear();
    if(searchCompletedEvent==null || searchCompletedEvent.hasZeroResults()){
        Log.i("Main", "updateSearchResultListView, no result");
        ((TextView)findViewById(R.id.main_search_results_empty_element)).setText(R.string.no_search_result_message);
    }else if(searchCompletedEvent.hasTooManyResults()) {
        Log.i("Main", "updateSearchResultListView, too many results");
        ((TextView)findViewById(R.id.main_search_results_empty_element)).setText(R.string.too_many_search_results_message);
    }else{
        List<FileInfo> list = searchCompletedEvent.getResultList();
        Log.i("Main", "updateSearchResultListView, result count = " + list.size());
        arrayAdapter.addAll(list);
    }
    arrayAdapter.notifyDataSetChanged();
    listView.setSelection(0);
}
 
Example 4
Source File: AppManager.java    From DistroHopper with GNU General Public License v3.0 6 votes vote down vote up
public void add (App app, boolean checkDuplicate, boolean sortAndNotifyAdapter)
{
	if (! (checkDuplicate && this.apps.contains (app)))
	{
		this.apps.add (app);

		if (sortAndNotifyAdapter)
		{
			this.sort ();

			ArrayAdapter adapter = (ArrayAdapter) this.gvDashHomeApps.getAdapter ();
			if (adapter != null)
				adapter.notifyDataSetChanged ();
		}
	}
}
 
Example 5
Source File: ConfigActivity.java    From Field-Book with GNU General Public License v2.0 6 votes vote down vote up
private void updateSetupList() {
    ArrayAdapter<String> ga = (ArrayAdapter) profileList.getAdapter();

    if (ga != null) {
        ga.clear();
    }

    String[] arrayData = prepareSetup();

    if (arrayData != null) {
        for (String string : arrayData) {
            ga.insert(string, ga.getCount());
        }
    }

    ga.notifyDataSetChanged();
}
 
Example 6
Source File: TestDatabaseActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onClick(View view) {
	@SuppressWarnings("unchecked")
	ArrayAdapter<Comment> adapter = (ArrayAdapter<Comment>) getListAdapter();
	Comment comment = null;
	switch (view.getId()) {
	case R.id.add:
		String[] comments = new String[] { "Cool", "Very nice", "Hate it" };
		int nextInt = new Random().nextInt(3);
		// Save the new comment to the database
		comment = datasource.createComment(comments[nextInt]);
		adapter.add(comment);
		break;
	case R.id.delete:
		if (getListAdapter().getCount() > 0) {
			comment = (Comment) getListAdapter().getItem(0);
			datasource.deleteComment(comment);
			adapter.remove(comment);
		}
		break;
	}
	adapter.notifyDataSetChanged();
}
 
Example 7
Source File: PSpinner.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
public PSpinner setData(String[] data) {
    this.mData = data;

    ArrayList<String> data_ = new ArrayList<>();
    data_.add("qq1");
    data_.add("qq2");

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_dropdown_item, data_);
    // adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    this.setAdapter(adapter);
    adapter.notifyDataSetChanged();

    return this;
}
 
Example 8
Source File: TrackIconUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public static void setIconSpinner(Spinner spinner, String iconValue) {
  @SuppressWarnings("unchecked")
  ArrayAdapter<StringBuilder> adapter = (ArrayAdapter<StringBuilder>) spinner.getAdapter();
  StringBuilder stringBuilder = adapter.getItem(0);
  stringBuilder.delete(0, stringBuilder.length());
  stringBuilder.append(iconValue);
  adapter.notifyDataSetChanged();
}
 
Example 9
Source File: ScannerDialogFragment.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
private static <T> void addData(@NonNull List<T> singleDataList,
                                @NonNull ArrayAdapter<T> cellLocationDataListAdapter,
                                @Nullable T data) {
    if (data != null) {
        if (!singleDataList.contains(data)) {
            singleDataList.add(data);
            cellLocationDataListAdapter.notifyDataSetChanged();
        }
    }
}
 
Example 10
Source File: CellLocationScannerDialogFragment.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
private static void addData(@NonNull List<CellLocationSingleData> singleDataList,
                            @NonNull ArrayAdapter<CellLocationSingleData> cellLocationDataListAdapter,
                            @Nullable CellLocationSingleData data) {
    if (data != null) {
        if (!singleDataList.contains(data)) {
            singleDataList.add(data);
            cellLocationDataListAdapter.notifyDataSetChanged();
        }
    }
}
 
Example 11
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ArrayAdapter a = (ArrayAdapter)lvItemList.getAdapter();
    CheckListItem temp = (CheckListItem) a.getItem(position);
    temp.setChecked(!temp.isChecked());
    a.notifyDataSetChanged();
}
 
Example 12
Source File: AppManager.java    From DistroHopper with GNU General Public License v3.0 5 votes vote down vote up
public boolean remove (App app)
{
	boolean modified = this.apps.remove (app);
	this.unpin (app, false);

	ArrayAdapter adapter = (ArrayAdapter) this.gvDashHomeApps.getAdapter ();
	if (adapter != null)
		adapter.notifyDataSetChanged ();

	return modified;
}
 
Example 13
Source File: MainActivity.java    From a-sync-browser with Mozilla Public License 2.0 4 votes vote down vote up
private void navigateToFolder(FileInfo fileInfo) {
    Log.d("navigateToFolder", "BEGIN");
    if (indexBrowser.isRoot() && PathUtils.isParent(fileInfo.getPath())) {
        showAllFoldersListView(); //navigate back to folder list
    } else {
        if (fileInfo.isDirectory()) {
            indexBrowser.navigateTo(fileInfo);
            FileInfo newFileInfo=PathUtils.isParent(fileInfo.getPath())?indexBrowser.getCurrentPathInfo():fileInfo;
            if (!indexBrowser.isCacheReadyAfterALittleWait()) {
                Log.d("navigateToFolder", "load folder cache bg");
                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected void onPreExecute() {
                        updateMainProgressBar(true,"open directory: " + (indexBrowser.isRoot() ? folderBrowser.getFolderInfo(indexBrowser.getFolder()).getLabel() : indexBrowser.getCurrentPathFileName()));
                    }

                    @Override
                    protected Void doInBackground(Void... voids) {
                        indexBrowser.waitForCacheReady();
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void aVoid) {
                        Log.d("navigateToFolder", "cache ready, navigate to folder");
                        updateMainProgressBar(false,null);
                        navigateToFolder(newFileInfo);
                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            } else {
                List<FileInfo> list = indexBrowser.listFiles();
                Log.i("navigateToFolder", "list for path = '" + indexBrowser.getCurrentPath() + "' list = " + list.size() + " records");
                Log.d("navigateToFolder", "list for path = '" + indexBrowser.getCurrentPath() + "' list = " + list);
                checkArgument(!list.isEmpty());//list must contain at least the 'parent' path
                ListView listView = (ListView) findViewById(R.id.main_folder_and_files_list_view);
                ArrayAdapter adapter = (ArrayAdapter) listView.getAdapter();
                adapter.clear();
                adapter.addAll(list);
                adapter.notifyDataSetChanged();
                listView.setSelection(0);
                saveCurrentFolder();
                ((TextView) findViewById(R.id.main_header_folder_label)).setText(indexBrowser.isRoot()
                        ?folderBrowser.getFolderInfo(indexBrowser.getFolder()).getLabel()
                        :newFileInfo.getFileName());
            }
        } else {
            pullFile(fileInfo);
        }
    }
    Log.d("navigateToFolder", "END");
}
 
Example 14
Source File: TodoTxtTouch.java    From endpoints-codelab-android with GNU General Public License v3.0 4 votes vote down vote up
private void setDrawerChoices() {
	m_drawerList.clearChoices();
	boolean haveContexts = false;
	boolean haveProjects = false;

	for (int i = 0; i < m_lists.size(); i++) {
		char sigil = m_lists.get(i).charAt(0);
		String item = m_lists.get(i).substring(1);

		if (sigil == '@' && m_app.m_contexts.contains(item)) {
			m_drawerList.setItemChecked(i, true);
			haveContexts = true;
		} else if (sigil == '+' && m_app.m_projects.contains(item)) {
			m_drawerList.setItemChecked(i, true);
			haveProjects = true;
		}
	}

	if (haveContexts) {
		if (!m_app.m_filters
				.contains(getString(R.string.filter_tab_contexts))) {
			m_app.m_filters.add(getString(R.string.filter_tab_contexts));
		}
	} else {
		m_app.m_filters.remove(getString(R.string.filter_tab_contexts));
		m_app.m_contexts = new ArrayList<String>();
	}

	if (haveProjects) {
		if (!m_app.m_filters
				.contains(getString(R.string.filter_tab_projects))) {
			m_app.m_filters.add(getString(R.string.filter_tab_projects));
		}
	} else {
		m_app.m_filters.remove(getString(R.string.filter_tab_projects));
		m_app.m_projects = new ArrayList<String>();
	}

	ArrayAdapter<?> adapter = (ArrayAdapter<?>) m_drawerList.getAdapter();

	if (adapter != null) {
		adapter.notifyDataSetChanged();
	}
}
 
Example 15
Source File: Adapters.java    From Android-Commons with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the items of the given adapter to the specified collection
 *
 * This operation includes removing the old items (if any) and adding the new ones
 *
 * Any listeners will only be informed about the final result
 *
 * @param adapter the adapter for which to set the items
 * @param content the collection that has the new items
 */
public static <T> void setItems(final ArrayAdapter<T> adapter, final Collection<T> content) {
   	adapter.setNotifyOnChange(false);

   	adapter.clear();
   	addAll(adapter, content);

   	adapter.notifyDataSetChanged();
   }