Android ListView - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ListView class.

This code example shows how to use the following methods: getChildAt, performItemClick, getAdapter
	} 
 
	@Test 
	public void is_item_click_available_from_list_fragment() { 
		ListView listView = (ListView) myListFragment.findViewById(android.R.id.list);
		long itemId = listView.getAdapter().getItemId(TESTED_CLICKED_INDEX);
		View view = listView.getChildAt(TESTED_CLICKED_INDEX);
 
		assertThat(myListFragment.listItemClicked).isFalse();
		listView.performItemClick(view, TESTED_CLICKED_INDEX, itemId);
		assertThat(myListFragment.listItemClicked).isTrue();
	} 
 
	public static void startFragment(Fragment fragment) {
		FragmentManager fragmentManager = new FragmentActivity().getSupportFragmentManager();
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
		fragmentTransaction.add(fragment, null);
		fragmentTransaction.commit();
	} 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setFastScrollEnabled, setDividerHeight
 
    } 
 
    @Override 
    protected void configureList(Activity activity, ListView listView) {
        super.configureList(activity, listView);
 
        listView.setFastScrollEnabled(true);
        listView.setDividerHeight(0);
 
        getListAdapter() 
                .addHeader(activity.getLayoutInflater()
                        .inflate(R.layout.news_list_item_labels, null));
    } 
 
    @Override 
    LogoutService getLogoutService() { 
        return logoutService;
    } 
 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getLeft, getRight, getTop
This code example shows how to use the following methods: addHeaderView, setAdapter, setEmptyView, setFocusable, setOnItemClickListener
		super.onCreate(savedInstanceState);
 
		if (listViewId != 0) {
			listView = findListViewById(listViewId);
			if (headerView() != null) { 
				listView.addHeaderView(headerView());
			} 
			listView.setOnItemClickListener(this);
			android.view.View emptyView = findViewById(android.R.id.empty);
			if (emptyView != null) {
				listView.setEmptyView(emptyView);
			} 
 
			adapter = Objects.createInstance(adapterClass, Context.class, this);
			listView.setAdapter(adapter);
			listView.setFocusable(true);
		} 
	} 
 
	/** 
	 * Called after ListAdapter has been loaded 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: addFooterView, getFooterViewsCount, setAdapter, setSelection
        mDataIterator = pullRequestService.pagePullRequests(new RepositoryId(mRepoOwner, mRepoName), mState);
    } 
     
    private void fillData(List<PullRequest> pullRequests) {
        if (pullRequests != null && !pullRequests.isEmpty()) {
            if (mListView.getFooterViewsCount() == 0) {
                mListView.addFooterView(mLoadingView);
                mListView.setAdapter(mAdapter);
            } 
            if (isLoadMore) {
                mAdapter.addAll(mAdapter.getCount(), pullRequests);
                mAdapter.notifyDataSetChanged();
            } 
            else { 
                mAdapter.clear();
                mAdapter.addAll(pullRequests);
                mAdapter.notifyDataSetChanged();
                mListView.setSelection(0);
            } 
        } 

9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setId
	@Override 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mHelper = new SlidingActivityHelper(this);
		mHelper.onCreate(savedInstanceState);
		ListView listView = new ListView(this);
		listView.setId(android.R.id.list);
		setContentView(listView);
	} 
 
	/* (non-Javadoc) 
	 * @see android.app.Activity#onPostCreate(android.os.Bundle) 
	 */ 
	@Override 
	public void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);
		mHelper.onPostCreate(savedInstanceState);
	} 
 
	/* (non-Javadoc) 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setOnCreateContextMenuListener, setOnItemClickListener
	private ListView agendaList;
	 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		this.agendaList = new ListView(getActivity());
		this.agendaList.setOnItemClickListener(agendaClickListener);
        this.agendaList.setOnCreateContextMenuListener(this);
 
		setHasOptionsMenu(true); 
		 
		return agendaList;
	} 
	 
	@Override 
	public void onResume() { 
		super.onResume(); 
		refresh(); 
	} 
 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getPaddingBottom, getPaddingTop, setPadding
    public View onCreateView(LayoutInflater inflater,
            ViewGroup container, Bundle savedInstanceState) {
        final View view = super.onCreateView(inflater, container, savedInstanceState);
        final ListView list = (ListView) view.findViewById(android.R.id.list);
        // our container already takes care of the padding 
        int paddingTop = list.getPaddingTop();
        int paddingBottom = list.getPaddingBottom();
        list.setPadding(0, paddingTop, 0, paddingBottom);
        return view;
    } 
 
    @Override 
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (preference == mPrivacyGuardDefault) {
            boolean value = (Boolean) newValue;
            Settings.Secure.putInt(getContentResolver(),
                    Settings.Secure.PRIVACY_GUARD_DEFAULT, value ? 1 : 0);
            return true; 
        } 
        return false; 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setFastScrollEnabled, setDividerHeight
 
    } 
 
    @Override 
    protected void configureList(Activity activity, ListView listView) {
        super.configureList(activity, listView);
 
        listView.setFastScrollEnabled(true);
        listView.setDividerHeight(0);
 
        getListAdapter().addHeader(activity.getLayoutInflater()
                        .inflate(R.layout.user_list_item_labels, null));
    } 
 
    @Override 
    LogoutService getLogoutService() { 
        return logoutService;
    } 
 
 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: getChildAt, getFirstVisiblePosition
 
	protected void onListItemClick (ListView listView, View view, int position, long id) {
		super.onListItemClick(listView, view, position, id);
 
		Editor editor = prefs.edit();
		editor.putInt("index", listView.getFirstVisiblePosition());
		editor.putInt("top", listView.getChildAt(0) == null ? 0 : listView.getChildAt(0).getTop());
		editor.commit();
 
		Object o = this.getListAdapter().getItem(position);
		String testName = o.toString();
 
		Bundle bundle = new Bundle();
		bundle.putString("test", testName);
		Intent intent = new Intent(this, GdxTestActivity.class);
		intent.putExtras(bundle);
 
		startActivity(intent);
	} 
 
Full Snippet Info
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android ListView Questions & Answers:

Other Android ListView Examples

1:	
2:	// Creating a button - Load More
3:	Button btnLoadMore = new Button(this);
-
1:	
2:	// Creating a button - Load More
3:	Button btnLoadMore = new Button(this);

Read More

14:		
15:		// List view
16:		private ListView lv;
17:		
18:		// Listview Adapter
-
36:	        						"Samsung Galaxy S3", "MacBook Air", "Mac Mini", "MacBook Pro"};
37:	        
38:	        lv = (ListView) findViewById(R.id.list_view);
39:	        inputSearch = (EditText) findViewById(R.id.inputSearch);
40:

Read More

21:	        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
22:	        
23:	        ListView lv = getListView();
24:	
25:	        // listening to single list item on click

Read More

1:	ListView listView = (ListView) findViewById(R.id.listview);
2:	listView.setAdapter(adapter);
3:	
-
1:	ListView listView = (ListView) findViewById(R.id.listview);
2:	listView.setAdapter(adapter);
3:

Read More

1:	ListView listView = getListView();
2:	listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
3:	listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

Read More

69:	
70:	    @Override 
71:	    public void onListItemClick(ListView l, View v, int position, long id) {
72:	        // Do something when a list item is clicked
73:	    }

Read More

See Code Examples for Android ListView Methods: