Java Code Examples for android.widget.AbsListView#setAdapter()

The following examples show how to use android.widget.AbsListView#setAdapter() . 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: ActivateProfileListFragment.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy()
{
    super.onDestroy();

    if (isAsyncTaskPendingOrRunning()) {
        this.asyncTaskContext.get().cancel(true);
    }

    AbsListView absListView;
    if (!ApplicationPreferences.applicationActivatorGridLayout)
        absListView = listView;
    else
        absListView = gridView;
    if (absListView != null)
        absListView.setAdapter(null);
    if (profileListAdapter != null)
        profileListAdapter.release();

    //if (activityDataWrapper != null)
    //    activityDataWrapper.invalidateDataWrapper();
    //activityDataWrapper = null;
}
 
Example 2
Source File: ScanActivity.java    From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scan);

    AbsListView listView = (AbsListView) findViewById(R.id.nodeListView);
    //create the adapter and set it to the list view
    mAdapter = new NodeArrayAdapter(this);
    listView.setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    listView.setOnItemClickListener(this);

    //add the already discovered nodes
    mAdapter.addAll(mManager.getNodes());

}
 
Example 3
Source File: WhiteListFragment.java    From android-overlay-protection with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_whitelist, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    mListView.setEmptyView(view.findViewById(android.R.id.empty));
    mListView.setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    return view;
}
 
Example 4
Source File: DetectedOverlayFragment.java    From android-overlay-protection with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_detectedoverlay, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    mListView.setEmptyView(view.findViewById(android.R.id.empty));
    mListView.setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    return view;
}
 
Example 5
Source File: CollectionFragment.java    From AnkiDroid-Wear with GNU General Public License v2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_collection, container, false);
    collectionListContainer = view.findViewById(R.id.collectionListContainer);
    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    mListView.setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    applySettings();
    return view;
}
 
Example 6
Source File: ListFragment.java    From ListItemFold with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_item_list, container, false);
    mAdapter = new ItemDataAdapter(getActivity());
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    mListView.setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);
    DetailAnimViewGroup wrapper = new DetailAnimViewGroup(inflater.getContext(), view, 0);
    loadData();
    return wrapper;
}
 
Example 7
Source File: SmartAdapter.java    From smart-adapters with MIT License 5 votes vote down vote up
/**
 * Assigns the created adapter to the given {@code AbsListView} inherited widget (ListView, GridView).
 *
 * @param widget ListView, GridView, ie any widget inheriting from {@code AbsListView}
 * @return assigned adapter
 */
public MultiAdapter into(@NonNull AbsListView widget) {
    validateMapper();
    MultiAdapter adapter = adapter();
    widget.setAdapter(adapter);
    return adapter;
}
 
Example 8
Source File: ChatterBoxMessageFragment.java    From pubnub-android-chat with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_chattmessage_list, container, false);

    // Set the adapter
    mListView = (AbsListView) view.findViewById(android.R.id.list);
    mListView.setAdapter(mAdapter);

    // Set OnItemClickListener so we can be notified on item clicks
    mListView.setOnItemClickListener(this);

    return view;
}
 
Example 9
Source File: SearchList.java    From moviedb-android with Apache License 2.0 5 votes vote down vote up
/**
 * Makes a new request to the server with the given query.
 */
public void search() {
    if (getActivity() != null) {
        listView = (AbsListView) getActivity().findViewById(R.id.movieslist);
        searchList = new ArrayList<>();
        searchAdapter = new SearchAdapter(getActivity(), R.layout.row, searchList);
        listView.setAdapter(searchAdapter);
        endlessScrollListener = new EndlessScrollListener();
        listView.setOnScrollListener(endlessScrollListener);
        final JSONAsyncTask request = new JSONAsyncTask();
        new Thread(new Runnable() {
            public void run() {
                try {
                    request.execute(MovieDB.url + "search/multi?query=" + getQuery() + "?&api_key=" + MovieDB.key).get(10000, TimeUnit.MILLISECONDS);
                } catch (TimeoutException | ExecutionException | InterruptedException e) {
                    request.cancel(true);
                    // we abort the http request, else it will cause problems and slow connection later
                    if (conn != null)
                        conn.disconnect();
                    toastLoadingMore.cancel();
                    if (getActivity() != null) {
                        getActivity().runOnUiThread(new Runnable() {
                            public void run() {
                                Toast.makeText(getActivity(), getResources().getString(R.string.timeout), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }
            }
        }).start();
    }
}
 
Example 10
Source File: GenresList.java    From moviedb-android with Apache License 2.0 5 votes vote down vote up
/**
 * Fired from the main activity. Makes a new request to the server.
 * Sets list, adapter, timeout.
 */
public void updateList() {
    if (getActivity() != null) {
        listView = (AbsListView) rootView.findViewById(R.id.genresList);
        genresList = new ArrayList<>();
        genresAdapter = new GenresAdapter(getActivity(), R.layout.genresrow, genresList);
        listView.setAdapter(genresAdapter);
        final JSONAsyncTask request = new JSONAsyncTask();
        new Thread(new Runnable() {
            public void run() {
                try {
                    request.execute(MovieDB.url + "genre/movie/list?&api_key=" + MovieDB.key).get(10000, TimeUnit.MILLISECONDS);
                } catch (TimeoutException | ExecutionException | InterruptedException e) {
                    request.cancel(true);
                    // we abort the http request, else it will cause problems and slow connection later
                    if (conn != null)
                        conn.disconnect();
                    if (spinner != null)
                        activity.hideView(spinner);
                    if (getActivity() != null) {
                        getActivity().runOnUiThread(new Runnable() {
                            public void run() {
                                Toast.makeText(getActivity(), getResources().getString(R.string.timeout), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                    backState = 0;
                }
            }
        }).start();
    }
}
 
Example 11
Source File: MainActivity.java    From QuickReturn with MIT License 5 votes vote down vote up
private void initialize(int layoutId) {
  setContentView(layoutId);
  offset = 0;
  ViewGroup viewGroup = (ViewGroup) findViewById(R.id.listView);
  topTextView = (TextView) findViewById(R.id.quickReturnTopTarget);
  bottomTextView = (TextView) findViewById(R.id.quickReturnBottomTarget);

  adapter = new ArrayAdapter<>(this, R.layout.list_item);
  addMoreItems(100);

  if (viewGroup instanceof AbsListView) {
    int numColumns = (viewGroup instanceof GridView) ? 3 : 1;
    AbsListView absListView = (AbsListView) viewGroup;
    absListView.setAdapter(new QuickReturnAdapter(adapter, numColumns));
  }

  QuickReturnAttacher quickReturnAttacher = QuickReturnAttacher.forView(viewGroup);
  quickReturnAttacher.addTargetView(bottomTextView, AbsListViewScrollTarget.POSITION_BOTTOM);
  topTargetView = quickReturnAttacher.addTargetView(topTextView,
      AbsListViewScrollTarget.POSITION_TOP,
      dpToPx(this, 50));

  if (quickReturnAttacher instanceof AbsListViewQuickReturnAttacher) {
    // This is the correct way to register an OnScrollListener.
    // You have to add it on the QuickReturnAttacher, instead
    // of on the viewGroup directly.
    AbsListViewQuickReturnAttacher
        attacher =
        (AbsListViewQuickReturnAttacher) quickReturnAttacher;
    attacher.addOnScrollListener(this);
    attacher.setOnItemClickListener(this);
    attacher.setOnItemLongClickListener(this);
  }
}
 
Example 12
Source File: StreamFragment.java    From gplus-haiku-client-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    AbsListView list = getListView();
    list.setAdapter(mAdapter);
    list.setOnItemClickListener(this);
}
 
Example 13
Source File: AbsListActivity.java    From CountDownTask with Apache License 2.0 4 votes vote down vote up
private void setList(List<CountDownInfo> list) {
    mListView = (AbsListView) findViewById(android.R.id.list);
    mAdapter = new CountDownAdapter(this, list);
    mListView.setAdapter(mAdapter);
}
 
Example 14
Source File: AbsListViewExampleActivity.java    From Paginate with Apache License 2.0 4 votes vote down vote up
@Override
protected void setupPagination() {
    if (paginate != null) {
        paginate.unbind();
    }
    handler.removeCallbacks(fakeCallback);
    adapter = new PersonAdapter(this, DataProvider.getRandomData(20));
    loading = false;
    page = 0;

    int layoutId;
    switch (absListViewType) {
        case LIST_VIEW:
            layoutId = R.layout.listview_layout;
            break;
        case GRID_VIEW:
            layoutId = R.layout.gridview_layout;
            break;
        default:
            layoutId = R.layout.listview_layout;
            break;
    }

    getContainer().removeAllViews();
    LayoutInflater.from(this).inflate(layoutId, getContainer(), true);

    AbsListView absListView = (AbsListView) findViewById(R.id.abs_list_view);
    if ((absListView instanceof ListView) && useHeaderAndFooter) {
        ListView listView = (ListView) absListView;
        listView.addHeaderView(LayoutInflater.from(this).inflate(R.layout.list_view_header, absListView, false));
        listView.addFooterView(LayoutInflater.from(this).inflate(R.layout.list_view_footer, absListView, false));
    }

    absListView.setAdapter(adapter);
    absListView.setOnItemClickListener(this);
    absListView.setOnItemLongClickListener(this);

    paginate = Paginate.with(absListView, this)
            .setOnScrollListener(this)
            .setLoadingTriggerThreshold(threshold)
            .addLoadingListItem(addLoadingRow)
            .setLoadingListItemCreator(customLoadingListItem ? new CustomLoadingListItemCreator() : null)
            .build();
}
 
Example 15
Source File: ActivateProfileListFragment.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(Void response) {
    super.onPostExecute(response);
    
    final ActivateProfileListFragment fragment = this.fragmentWeakRef.get();
    
    if ((fragment != null) && (fragment.isAdded())) {
        progressBarHandler.removeCallbacks(progressBarRunnable);
        fragment.progressBar.setVisibility(View.GONE);

        // get local profileList
        this.dataWrapper.fillProfileList(true, applicationActivatorPrefIndicator);
        // set copy local profile list into activity profilesDataWrapper
        fragment.activityDataWrapper.copyProfileList(this.dataWrapper);

        // get local eventTimelineList
        this.dataWrapper.fillEventTimelineList();
        // set copy local event timeline list into activity profilesDataWrapper
        fragment.activityDataWrapper.copyEventTimelineList(this.dataWrapper);

        synchronized (fragment.activityDataWrapper.profileList) {
            if (fragment.activityDataWrapper.profileList.size() == 0) {
                fragment.textViewNoData.setVisibility(View.VISIBLE);

                // no profile in list, start Editor

                //noinspection ConstantConditions
                Intent intent = new Intent(fragment.getActivity().getBaseContext(), EditorProfilesActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                intent.putExtra(PPApplication.EXTRA_STARTUP_SOURCE, PPApplication.STARTUP_SOURCE_ACTIVATOR_START);
                fragment.getActivity().startActivity(intent);

                try {
                    fragment.getActivity().finish();
                } catch (Exception e) {
                    PPApplication.recordException(e);
                }

                return;
            }
        }

        fragment.profileListAdapter = new ActivateProfileListAdapter(fragment, /*fragment.profileList, */fragment.activityDataWrapper);

        AbsListView absListView;
        if (!applicationActivatorGridLayout)
            absListView = fragment.listView;
        else
            absListView = fragment.gridView;
        absListView.setAdapter(fragment.profileListAdapter);

        fragment.doOnStart();

        //noinspection ConstantConditions
        final Handler handler = new Handler(fragment.getActivity().getMainLooper());
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (fragment.getActivity() != null) {
                    if (!fragment.getActivity().isFinishing())
                        ((ActivateProfileActivity) fragment.getActivity()).startTargetHelpsActivity();
                }
            }
        }, 500);

    }
}
 
Example 16
Source File: ListDemoActivity.java    From android-Stupid-Adapter with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	if (getIntent() != null)
		type = getIntent().getIntExtra(LIST_TYPE_INT, 0);
	switch (type) {

	case type_grid_view:
		setContentView(R.layout.activity_grid_demo);
		VlistViewHolder.type = R.layout.vlist_view_holder2;
		break;
	default:
	case type_list_view:
		setContentView(R.layout.activity_list_demo);
		VlistViewHolder.type = R.layout.vlist_view_holder;
	}
	adapter = new XAdapter2<Vlist>(this, null, VlistViewHolder.class);
	adapter.setClickItemListener(this);// 设置item的点击事件;
	adapter.setLongClickItemListener(this);// 设置item的长按事件;
	adapter.setOnDataChang(new IXDataListener() {

		TextView textView = new TextView(getBaseContext());
		{
			textView.setGravity(Gravity.CENTER);
			textView.setText("没有数据");
			ViewGroup v = (ViewGroup) findViewById(getLayoutId());
			v.addView(textView, 0);
		}

		@Override
		public void onDataEmpty() {

			textView.setVisibility(View.VISIBLE);

		}

		@Override
		public void onDataChange() {
			if (textView.getVisibility() == View.VISIBLE)
				textView.setVisibility(View.GONE);
		}
	});

	listView = (AbsListView) findViewById(R.id.bton_listview);
	listView.setAdapter(adapter);
	listView.setOnScrollListener(adapter.getOnScrollListener(null));

	swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swrefresh);
	swipeRefreshLayout.setOnRefreshListener(this);
	onRefresh();

}