android.widget.ListView Java Examples

The following examples show how to use android.widget.ListView. 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: MainActivity.java    From Android-Example with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
  
 metrics = new DisplayMetrics();
 getWindowManager().getDefaultDisplay().getMetrics(metrics);

 listview = new ListView(this);
 listview.setFadingEdgeLength(0);
 ArrayList<String> strings = new ArrayList<String>();

 for (int i = 0; i < 300; i++) {
  strings.add("Item:#" + (i + 1));
 }

 MainAdapter mAdapter = new MainAdapter(this, strings, metrics);
 listview.setAdapter(mAdapter);
 setContentView(listview);
}
 
Example #2
Source File: NavigationDrawerFragment.java    From abelana with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView
            .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                                        int position, long id) {
                    selectItem(position);
                }
            });

    DrawerListAdapter adapter = new DrawerListAdapter(getActivity()
            .getApplicationContext(), mNavItems);
    mDrawerListView.setAdapter(adapter);
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    mDrawerListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    return mDrawerListView;
}
 
Example #3
Source File: SavedFragment.java    From minx with MIT License 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    enterPinTxt = (FontText) getView().findViewById(R.id.enter_pin_txt);
    userArchivePinTxt = (EditText) getView().findViewById(R.id.userArchivePinTxt);
    btnRetrieveArchive = (Button) getView().findViewById(R.id.btnRetrieveArchive);
    listViewSaved = (ListView) getView().findViewById(R.id.saved_list);

    if(checkPINEnabled()){
        enterPinTxt.setVisibility(View.GONE);
        userArchivePinTxt.setVisibility(View.GONE);
        btnRetrieveArchive.setVisibility(View.GONE);
        loadSavedData();
    }else{
        settingsPreferences = new SettingsPreferences(getActivity());
        if(!settingsPreferences.retrievePINTemp()){
            loadPIN();
        }else{
            enterPinTxt.setVisibility(View.GONE);
            userArchivePinTxt.setVisibility(View.GONE);
            btnRetrieveArchive.setVisibility(View.GONE);
            loadSavedData();
        }
    }
}
 
Example #4
Source File: NavigationDrawerFragment.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(
            R.layout.recyclerview_playground_fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    mDrawerListView.setAdapter(new ArrayAdapter<String>(
            getActivity(),
            android.R.layout.simple_list_item_activated_1,
            android.R.id.text1,
            new String[]{
                    "title_section1",
                    "title_section2",
                    "title_section3",
                    "title_section4",
            }));
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
    return mDrawerListView;
}
 
Example #5
Source File: DonationsDialog.java    From Orin with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostExecute(List<SkuDetails> skuDetails) {
    super.onPostExecute(skuDetails);
    DonationsDialog dialog = donationDialogWeakReference.get();
    if (dialog == null) return;

    if (skuDetails == null || skuDetails.isEmpty()) {
        dialog.dismiss();
        return;
    }

    View customView = ((MaterialDialog) dialog.getDialog()).getCustomView();
    //noinspection ConstantConditions
    customView.findViewById(R.id.progress_container).setVisibility(View.GONE);
    ListView listView = ButterKnife.findById(customView, R.id.list);
    listView.setAdapter(new SkuDetailsAdapter(dialog, skuDetails));
    listView.setVisibility(View.VISIBLE);
}
 
Example #6
Source File: PlacePickerFragment.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
@Override
void setupViews(ViewGroup view) {
    if (showSearchBox) {
        ListView listView = (ListView) view.findViewById(R.id.com_facebook_picker_list_view);

        View searchHeaderView = getActivity().getLayoutInflater().inflate(
                R.layout.com_facebook_picker_search_box, listView, false);

        listView.addHeaderView(searchHeaderView, null, false);

        searchBox = (EditText) view.findViewById(R.id.com_facebook_picker_search_text);

        searchBox.addTextChangedListener(new SearchTextWatcher());
        if (!TextUtils.isEmpty(searchText)) {
            searchBox.setText(searchText);
        }
    }
}
 
Example #7
Source File: ResultActivityTest.java    From aedict with GNU General Public License v3.0 6 votes vote down vote up
public void testEdictExternSearch() throws Exception {
	final Intent i = new Intent(getInstrumentation().getContext(), ResultActivity.class);
	i.setAction(ResultActivity.EDICT_ACTION_INTERCEPT);
	i.putExtra(ResultActivity.EDICT_INTENTKEY_KANJIS, "空白");
	tester.startActivity(i);
	assertTrue(tester.getText(R.id.textSelectedDictionary).contains("Default"));
	final ListView lv = getActivity().getListView();
	assertEquals(1, lv.getCount());
	DictEntry entry = (DictEntry) lv.getItemAtPosition(0);
	assertEquals("Searching", entry.english);
	Thread.sleep(500);
	final Intent i2 = getStartedActivityIntent();
	final List<DictEntry> result = (List<DictEntry>) i2.getSerializableExtra(ResultActivity.INTENTKEY_RESULT_LIST);
	entry = result.get(0);
	assertEquals("(adj-na,n,adj-no) blank space/vacuum/space/null (NUL)/(P)", entry.english);
	assertEquals("空白", entry.getJapanese());
	assertEquals("くうはく", entry.reading);
	assertEquals(1, result.size());
}
 
Example #8
Source File: TreeListViewAdapter.java    From AndroidTreeView with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 创建一个新的实例 TreeListViewAdapter. 
 * @param context			上下文
 * @param mTree				展示用的ListView
 * @param datas				数据集
 * @param defaultLevel		默认展开层级
 * @throws IllegalArgumentException 
 * @throws IllegalAccessException 
 */
public TreeListViewAdapter(Context context,ListView tree, List<T> datas, int defaultExpandLevel) throws IllegalAccessException, IllegalArgumentException {
	mContext = context;
	mInflater = LayoutInflater.from(context);
	mAllNodes = TreeHelper.getSortedNodes(datas, defaultExpandLevel);
	mVisibleNodes = TreeHelper.fliterVisibleNodes(mAllNodes);
	for (Node node : mVisibleNodes) {
		Log.e("TAG", "显示--"+node.getName());
	}
	mTree = tree;
	
	mTree.setOnItemClickListener(new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			expandOrCollapse(position);
			
			if (mListener != null) {
				mListener.onClick(mVisibleNodes.get(position), position);
			}
		}
	});
}
 
Example #9
Source File: HeaderActivity.java    From PullRefreshView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_header);

    flingLayout = (FlingLayout) findViewById(R.id.root);
    listView = (ListView) findViewById(R.id.list);
    footerView = (BaseFooterView) findViewById(R.id.footer);
    animHeader = findViewById(R.id.anim_header);
    scrollGeter = ViewScrollUtil.getScrollGeter(listView);

    list = getData(15);

    adapter = new ArrayAdapter(this, R.layout.item, list);

    listView.setAdapter(adapter);
    flingLayout.setOnScrollListener(this);
    listView.setOnScrollListener(this);
    footerView.setOnLoadListener(this);
}
 
Example #10
Source File: ChooseTagActivity.java    From sprinkles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.acitivty_choose_tag);

	mNoteId = getIntent().getLongExtra(EXTRA_NOTE_ID, -1);

	Query.many(Tag.class, "select * from Tags").getAsync(
			getLoaderManager(), onTagsLoaded);
	Query.many(NoteTagLink.class,
			"select * from NoteTagLinks where note_id=?", mNoteId).getAsync(
			getLoaderManager(), onLinksLoaded, Note.class, Tag.class);

	mListView = (ListView) findViewById(R.id.list);
	mListView.setEmptyView(findViewById(R.id.empty));
	mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
	mListView.setOnItemClickListener(onListItemClicked);

	mAdapter = new TagsAdapter(this);
	mListView.setAdapter(mAdapter);
}
 
Example #11
Source File: ListViewUtil.java    From MVPAndroidBootstrap with Apache License 2.0 6 votes vote down vote up
/**** Method for Setting the Height of the ListView dynamically.
 **** Hack to fix the issue of not showing all the items of the ListView
 **** when placed inside a ScrollView  ****/
public static void setListViewHeightBasedOnChildren(ListView listView) {
    ListAdapter mAdapter = listView.getAdapter();

    int totalHeight = 0;

    for (int i = 0; i < mAdapter.getCount(); i++) {
        View mView = mAdapter.getView(i, null, listView);

        mView.measure(
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),

                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

        totalHeight += mView.getMeasuredHeight();
        Log.w("HEIGHT" + i, String.valueOf(totalHeight));

    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight
            + (listView.getDividerHeight() * (mAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}
 
Example #12
Source File: VideoSelectorActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
public void bindViews() {
    lv_videos = (ListView) this.findViewById(R.id.lv_videos);
    QtNewActionBar actionBar = (QtNewActionBar) this.findViewById(R.id.my_action_bar);
    setNewActionBar(actionBar);
    setActionBarTitle(R.string.atom_ui_title_select_video);
    setActionBarRightIcon(R.string.atom_ui_new_send);
    setActionBarRightIconClick(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mSelectedNumber == -1) {
                Toast.makeText(VideoSelectorActivity.this, getString(R.string.atom_ui_tip_select_video), Toast.LENGTH_SHORT).show();
            } else {
                Intent resultIntent = new Intent();
                resultIntent.putExtra("filepath", videos.get(mSelectedNumber).path);
                setResult(Activity.RESULT_OK, resultIntent);
                finish();
            }
        }
    });

}
 
Example #13
Source File: SimpleHomeActivity.java    From FlycoPageIndicator with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ListView lv = new ListView(context);
    lv.setCacheColorHint(Color.TRANSPARENT);
    lv.setFadingEdgeLength(0);
    lv.setAdapter(new SimpleHomeAdapter(context, items));

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(context, classes[position]);
            startActivity(intent);
        }
    });

    setContentView(lv);
}
 
Example #14
Source File: LauncherActivity.java    From CountDownTask with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ListView listView = new ListView(this);
    setContentView(listView);

    Log.d(TAG, TAG + " task id: " + getTaskId());

    Intent intent = getIntent();
    String path = intent.getStringExtra(getPackageName() + ".Path");

    if (path == null) {
        path = "";
    }

    listView.setAdapter(new SimpleAdapter(this, getData(path),
            android.R.layout.simple_list_item_1, new String[]{"title"},
            new int[]{android.R.id.text1}));
    listView.setTextFilterEnabled(true);
    listView.setOnItemClickListener(this);
}
 
Example #15
Source File: ListFragment.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    String item = (String) l.getAdapter().getItem(position);

    if (item.equals(HANDLER)) {
        getFragmentManager().beginTransaction()
                .replace(R.id.root_container, HandlerFragment.newInstance())
                .addToBackStack(null)
                .commit();
    } else if (item.equals(WEB_VIEW)) {
        getFragmentManager().beginTransaction()
                .replace(R.id.root_container, WebViewFragment.newInstance())
                .addToBackStack(null)
                .commit();
    }

    ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
 
Example #16
Source File: MainActivity.java    From checkey with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // Start the CAB using the ActionMode.Callback defined above
    ActionBarActivity activity = (ActionBarActivity) getActivity();
    selectedItem = position;
    AppEntry appEntry = (AppEntry) adapter.getItem(selectedItem);
    showCertificateInfo(activity, appEntry.getPackageName());
}
 
Example #17
Source File: KnockSequenceListFragment.java    From juicessh-portknocker with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.fragment_main, container, false);

    this.connectionList = (Spinner) layout.findViewById(R.id.connection_spinner);
    this.connectionListAdapter = new ConnectionSpinnerAdapter(getActivity());
    connectionList.setAdapter(connectionListAdapter);

    this.knockItemList = (ListView) layout.findViewById(R.id.knock_item_list);
    this.connectButton = (Button) layout.findViewById(R.id.connect_button);
    this.shortcutButton = (Button) layout.findViewById(R.id.shortcut_button);

    return layout;
}
 
Example #18
Source File: WishlistListFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
	// The id argument will be the Skill ID; CursorAdapter gives us this for free
	if (mActionMode == null) {
           mListView.setItemChecked(position, false);
		Intent i = new Intent(getActivity(), WishlistDetailActivity.class);
		i.putExtra(WishlistDetailActivity.EXTRA_WISHLIST_ID, id);
		startActivity(i);
	} 
	// Contextual action bar options
	else {
           highlightSelection(position);
           mActionMode.setTag(position);
	}
}
 
Example #19
Source File: CacheFragment.java    From ksyhttpcache_android with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_cache, container, false);
    cached_list = (ListView) view.findViewById(R.id.cached_list);
    initlist();

    return view;
}
 
Example #20
Source File: OtherTicketInfoFragment.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	View v = inflater.inflate(R.layout.fragment_other_ticket_info, null);
	ListView lvInfos = (ListView) v.findViewById(R.id.otherTicketInfo_lvInfos);
	MyDatabase myDB = new MyDatabase(this.getActivity());
	mAdapter= new SimpleAdapter(this.getActivity(),mLstDatas, R.layout.item_buy_ticket_info,
			new String[]{MyDatabase.KEY, MyDatabase.VALUE},
			new int[]{R.id.item_buy_ticket_info_tvQuestion, R.id.item_buy_ticket_info_tvAnswer}
			);
	lvInfos.setAdapter(mAdapter);
	myDB.closeDB();
	notifyAdapterDataChanged(myDB.getTicketInfos(0));
	return v;
}
 
Example #21
Source File: NiceSpinner.java    From nice-spinner with Apache License 2.0 5 votes vote down vote up
/**
 * only applicable when popup is shown .
 * @param view
 * @param position
 * @param id
 */
public void performItemClick(View view, int position, int id) {
    showDropDown();
    final ListView listView = popupWindow.getListView();
    if(listView != null) {
        listView.performItemClick(view, position, id);
    }
}
 
Example #22
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public static void stopListViewScrollingAndScrollToTop(ListView listView) {
    Runnable runnable = JavaReflectionUtility.getValue(listView, "mFlingRunnable");
    listView.removeCallbacks(runnable);
    listView.setSelection(Math.min(listView.getFirstVisiblePosition(), 5));
    listView.smoothScrollToPosition(0);

}
 
Example #23
Source File: ServersListActivity.java    From EasyVPN-Free with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_servers_list);

    if (!VpnStatus.isVPNActive())
        connectedServer = null;

    listView = (ListView) findViewById(R.id.list);
}
 
Example #24
Source File: ClassTable.java    From iSCAU-Android with GNU General Public License v3.0 5 votes vote down vote up
private void buildDayClassTableAdapter(List<ClassModel> dayClassList){
    ListView classListView = UIHelper.buildClassListView(getSherlockActivity());
    ClassAdapter  cAdapter = ClassAdapter_.getInstance_(getSherlockActivity());
    BaseAdapter   _adapter = UIHelper.buildEffectAdapter(cAdapter, (AbsListView) classListView,EXPANDABLE_ALPHA);

    cAdapter.addAll(dayClassList);
    cAdapter.setFragment(this);
    classListView.setAdapter(_adapter);
    listViews.add(classListView);

}
 
Example #25
Source File: SwipeDismissListViewTouchListener.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructs a new swipe-to-dismiss touch listener for the given list view.
 *
 * @param listView The list view whose items should be dismissable.
 * @param callback The callback to trigger when the user has indicated that she would like to
 *                 dismiss one or more list items.
 */
public SwipeDismissListViewTouchListener(ListView listView, OnDismissCallback callback) {
    ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime = listView.getContext().getResources().getInteger(
            android.R.integer.config_shortAnimTime);
    mListView = listView;
    mCallback = callback;
}
 
Example #26
Source File: CircleMenu.java    From CircleMenu with MIT License 5 votes vote down vote up
private void setupMenu() {
    mListView = new ListView(mContext);
    mListView.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mListView.setOnItemClickListener(this);
    addView(mListView);
}
 
Example #27
Source File: ViewHelper.java    From DMusic with Apache License 2.0 5 votes vote down vote up
/**
 * 判断 ListView 是否已经滚动到底部
 *
 * @param listView 需要被判断的 ListView
 * @return
 */
public static boolean isListViewAlreadyAtBottom(ListView listView) {
    if (listView.getAdapter() == null || listView.getHeight() == 0) {
        return false;
    }

    if (listView.getLastVisiblePosition() == listView.getAdapter().getCount() - 1) {
        View lastItemView = listView.getChildAt(listView.getChildCount() - 1);
        if (lastItemView != null && lastItemView.getBottom() == listView.getHeight()) {
            return true;
        }
    }
    return false;
}
 
Example #28
Source File: SuntimesSettingsActivityTest.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
public static void verifyUISettings_theme(Activity activity)
{
    DataInteraction themePref = onData(allOf( is(instanceOf(Preference.class)), withKey("app_appearance_theme"))).inAdapterView(allOf(hasFocus(), is(instanceOf(ListView.class))));
    themePref.check(assertEnabled);

    String themeName = AppSettings.loadThemePref(activity);
    String themeDisplay = getThemeDisplayString(activity, themeName);
    DataInteraction themePref_text = themePref.onChildView(allOf(withClassName(is(TextView.class.getName())), withText(themeDisplay)));
    themePref_text.check(assertShown);
}
 
Example #29
Source File: PullToRefreshListView.java    From iSCAU-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected ListView createRefreshableView(Context context, AttributeSet attrs) {
	ListView lv = createListView(context, attrs);

	// Set it to this so it can be used in ListActivity/ListFragment
	lv.setId(android.R.id.list);
	return lv;
}
 
Example #30
Source File: AccountsManagementActivity.java    From Shaarlier with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    final ListView accountsListView = findViewById(R.id.accountListView);
    AccountsSource accountsSource = new AccountsSource(getApplicationContext());
    try {
        accountsSource.rOpen();
        List<ShaarliAccount> accountsList = accountsSource.getAllAccounts();
        ArrayAdapter<ShaarliAccount> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, accountsList);

        accountsListView.setAdapter(adapter);

        if (accountsList.isEmpty())
            findViewById(R.id.noAccountToShow).setVisibility(View.VISIBLE);
        else
            findViewById(R.id.noAccountToShow).setVisibility(View.GONE);


    } catch (SQLException e) {
        Log.e("DB_ERROR", e.toString());
    } finally {
        accountsSource.close();
    }
    accountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            ShaarliAccount clickedAccount = (ShaarliAccount) accountsListView.getItemAtPosition(position);

            addOrEditAccount(clickedAccount);
        }
    });
}