android.widget.AbsListView#setAdapter ( )源码实例Demo

下面列出了android.widget.AbsListView#setAdapter ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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;
}
 
源代码2 项目: BlueSTSDK_Android   文件: ScanActivity.java
@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());

}
 
@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;
}
 
@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;
}
 
源代码5 项目: AnkiDroid-Wear   文件: CollectionFragment.java
@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;
}
 
源代码6 项目: ListItemFold   文件: ListFragment.java
@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;
}
 
源代码7 项目: smart-adapters   文件: SmartAdapter.java
/**
 * 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;
}
 
@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;
}
 
源代码9 项目: moviedb-android   文件: SearchList.java
/**
 * 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();
    }
}
 
源代码10 项目: moviedb-android   文件: GenresList.java
/**
 * 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();
    }
}
 
源代码11 项目: QuickReturn   文件: MainActivity.java
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);
  }
}
 
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    AbsListView list = getListView();
    list.setAdapter(mAdapter);
    list.setOnItemClickListener(this);
}
 
源代码13 项目: CountDownTask   文件: AbsListActivity.java
private void setList(List<CountDownInfo> list) {
    mListView = (AbsListView) findViewById(android.R.id.list);
    mAdapter = new CountDownAdapter(this, list);
    mListView.setAdapter(mAdapter);
}
 
源代码14 项目: Paginate   文件: AbsListViewExampleActivity.java
@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();
}
 
@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);

    }
}
 
源代码16 项目: android-Stupid-Adapter   文件: ListDemoActivity.java
@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();

}