List of usage examples for android.widget ListView addHeaderView
public void addHeaderView(View v)
From source file:com.cleanwiz.applock.ui.adapter.MainPagerAdapter.java
@SuppressLint("InflateParams") private View buildLockView() { View view = mInflater.inflate(R.layout.pager_applock, null); ListView listView = (ListView) view.findViewById(R.id.lv_apps); final LockAdapter adapter = new LockAdapter(mContext); View header = mInflater.inflate(R.layout.pager_applock_header, null); final TextView tvSortAlpha = (TextView) header.findViewById(R.id.sort_alpha); final TextView tvSortDefault = (TextView) header.findViewById(R.id.sort_default); final int colorRed = mContext.getResources().getColor(R.color.text_red); final int colorBlack = mContext.getResources().getColor(R.color.md_black_1); View.OnClickListener onSort = new View.OnClickListener() { @Override/* w ww . j av a2s .c o m*/ public void onClick(View v) { switch (v.getId()) { case R.id.sort_alpha: tvSortAlpha.setTextColor(colorRed); tvSortDefault.setTextColor(colorBlack); adapter.onSort(LockAdapter.SORT_ALPHA); break; case R.id.sort_default: tvSortAlpha.setTextColor(colorBlack); tvSortDefault.setTextColor(colorRed); adapter.onSort(LockAdapter.SORT_DEFAULT); break; } } }; tvSortAlpha.setOnClickListener(onSort); tvSortDefault.setOnClickListener(onSort); listView.addHeaderView(header); listView.setAdapter(adapter); return view; }
From source file:com.hughes.android.dictionary.DictionaryActivity.java
void onLanguageButtonLongClick(final Context context) { final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.select_dictionary_dialog); dialog.setTitle(R.string.selectDictionary); final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice(null); ListView listView = (ListView) dialog.findViewById(android.R.id.list); final Button button = new Button(listView.getContext()); final String name = getString(R.string.dictionaryManager); button.setText(name);//w w w . j a v a 2s. com final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(), DictionaryManagerActivity.getLaunchIntent(getApplicationContext())) { @Override protected void onGo() { dialog.dismiss(); DictionaryActivity.this.finish(); } }; button.setOnClickListener(intentLauncher); listView.addHeaderView(button); listView.setAdapter(new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { final DictionaryInfo dictionaryInfo = getItem(position); final LinearLayout result = new LinearLayout(parent.getContext()); for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) { final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i); final View button = application.createButton(parent.getContext(), dictionaryInfo, indexInfo); final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(), getLaunchIntent(getApplicationContext(), application.getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName, searchView.getQuery().toString())) { @Override protected void onGo() { dialog.dismiss(); DictionaryActivity.this.finish(); } }; button.setOnClickListener(intentLauncher); if (i == indexIndex && dictFile != null && dictFile.getName().equals(dictionaryInfo.uncompressedFilename)) { button.setPressed(true); } result.addView(button); } final TextView nameView = new TextView(parent.getContext()); final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename); nameView.setText(name); final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.width = 0; layoutParams.weight = 1.0f; nameView.setLayoutParams(layoutParams); nameView.setGravity(Gravity.CENTER_VERTICAL); result.addView(nameView); return result; } @Override public long getItemId(int position) { return position; } @Override public DictionaryInfo getItem(int position) { return installedDicts.get(position); } @Override public int getCount() { return installedDicts.size(); } }); dialog.show(); }
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle(R.string.details); mContext = getActivity();//from w w w. j a v a2s . c om ListView listView = getListView(); mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); View header = getActivity().getLayoutInflater().inflate(R.layout.fragment_result, null, false); mPpmText = (TextView) header.findViewById(R.id.ppmText); mDateView = (TextView) header.findViewById(R.id.testDate); mTitleView = (TextView) header.findViewById(R.id.titleView); mResultTextView = (TextView) header.findViewById(R.id.result); mAddressText = (TextView) header.findViewById(R.id.address1); mAddress2Text = (TextView) header.findViewById(R.id.address2); mAddress3Text = (TextView) header.findViewById(R.id.address3); mSourceText = (TextView) header.findViewById(R.id.sourceType); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); mId = getArguments().getLong(getString(R.string.currentTestId)); mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, mFolderName, false)); long locationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); final ArrayList<String> imagePaths = FileUtils.getFilePaths(getActivity(), mFolderName, "/small/", locationId); if (mId > -1) { if (!directory.exists()) { Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); goBack(); } else if (imagePaths.size() > 0) { displayResult(); } else { FileUtils.deleteFolder(getActivity(), mLocationId, mFolderName); goBack(); } } ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(-1, true); drawerList.setSelection(-1); assert listView != null; listView.addHeaderView(header); // Gradient shading for title assert header != null; //Collections.sort(imagePaths); GalleryListAdapter adapter = new GalleryListAdapter(getActivity(), mTestTypeId, mId, imagePaths, true); setListAdapter(adapter); Shader textShader = new LinearGradient(0, 0, 0, mTitleView.getPaint().getTextSize(), new int[] { getResources().getColor(R.color.textGradientStart), getResources().getColor(R.color.textGradientEnd) }, new float[] { 0, 1 }, Shader.TileMode.CLAMP); mTitleView.getPaint().setShader(textShader); }
From source file:com.nachiket.titan.LibraryPagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { int type = mTabOrder[position]; ListView view = mLists[type]; if (view == null) { LibraryActivity activity = mActivity; LayoutInflater inflater = activity.getLayoutInflater(); LibraryAdapter adapter;/*from w w w . j a v a 2s .com*/ TextView header = null; switch (type) { case MediaUtils.TYPE_ARTIST: adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, null); mArtistAdapter.setExpandable(mSongsPosition != -1 || mAlbumsPosition != -1); mArtistHeader = header = (TextView) inflater.inflate(R.layout.library_row, null); break; case MediaUtils.TYPE_ALBUM: adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter); mAlbumAdapter.setExpandable(mSongsPosition != -1); mPendingAlbumLimiter = null; mAlbumHeader = header = (TextView) inflater.inflate(R.layout.library_row, null); break; case MediaUtils.TYPE_SONG: adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter); mPendingSongLimiter = null; mSongHeader = header = (TextView) inflater.inflate(R.layout.library_row, null); break; case MediaUtils.TYPE_PLAYLIST: adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null); break; case MediaUtils.TYPE_GENRE: adapter = mGenreAdapter = new MediaAdapter(activity, MediaUtils.TYPE_GENRE, null); mGenreAdapter.setExpandable(mSongsPosition != -1); break; case MediaUtils.TYPE_FILE: adapter = mFilesAdapter = new FileSystemAdapter(activity, mPendingFileLimiter); mPendingFileLimiter = null; break; default: throw new IllegalArgumentException("Invalid media type: " + type); } view = (ListView) inflater.inflate(R.layout.listview, null); view.setOnCreateContextMenuListener(this); view.setOnItemClickListener(this); view.setTag(type); if (header != null) { header.setText(mHeaderText); header.setTag(type); view.addHeaderView(header); } view.setAdapter(adapter); if (type != MediaUtils.TYPE_FILE) loadSortOrder((MediaAdapter) adapter); enableFastScroll(view); adapter.setFilter(mFilter); mAdapters[type] = adapter; mLists[type] = view; mRequeryNeeded[type] = true; } requeryIfNeeded(type); container.addView(view); return view; }
From source file:ch.teamuit.android.soundplusplus.LibraryPagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { int type = mTabOrder[position]; ListView view = mLists[type]; if (view == null) { LibraryActivity activity = mActivity; LayoutInflater inflater = activity.getLayoutInflater(); LibraryAdapter adapter;/*from w w w. j av a 2 s. co m*/ DraggableRow header = null; switch (type) { case MediaUtils.TYPE_ARTIST: adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, mPendingArtistLimiter, activity); mArtistAdapter.setExpandable(mSongsPosition != -1 || mAlbumsPosition != -1); mArtistHeader = header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_ALBUM: adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter, activity); mAlbumAdapter.setExpandable(mSongsPosition != -1); mPendingAlbumLimiter = null; mAlbumHeader = header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_SONG: adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter, activity); mPendingSongLimiter = null; mSongHeader = header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_PLAYLIST: adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null, activity); break; case MediaUtils.TYPE_GENRE: adapter = mGenreAdapter = new MediaAdapter(activity, MediaUtils.TYPE_GENRE, null, activity); mGenreAdapter.setExpandable(mSongsPosition != -1); break; case MediaUtils.TYPE_FILE: adapter = mFilesAdapter = new FileSystemAdapter(activity, mPendingFileLimiter); mPendingFileLimiter = null; break; default: throw new IllegalArgumentException("Invalid media type: " + type); } view = (ListView) inflater.inflate(R.layout.listview, null); view.setOnCreateContextMenuListener(this); view.setOnItemClickListener(this); view.setTag(type); if (header != null) { header.getTextView().setText(mHeaderText); header.setTag(new ViewHolder()); // behave like a normal library row view.addHeaderView(header); } view.setAdapter(adapter); if (type != MediaUtils.TYPE_FILE) loadSortOrder((MediaAdapter) adapter); adapter.setFilter(mFilter); mAdapters[type] = adapter; mLists[type] = view; mRequeryNeeded[type] = true; } requeryIfNeeded(type); container.addView(view); return view; }
From source file:org.kontalk.ui.ComposeMessageFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // setListAdapter() is post-poned ListView list = getListView(); list.setFastScrollEnabled(true);//from w w w . j a v a 2 s. c o m setMultiChoiceModeListener(this); // add header view (this must be done before setting the adapter) mHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.message_list_header, list, false); mNextPageButton = mHeaderView.findViewById(R.id.load_next_page); mNextPageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // disable button in the meantime enableHeaderView(false); // start query for the next page startMessagesQuery(mQueryHandler.getLastId()); } }); list.addHeaderView(mHeaderView); // set custom background (if any) ImageView background = (ImageView) getView().findViewById(R.id.background); Drawable bg = Preferences.getConversationBackground(getActivity()); if (bg != null) { background.setScaleType(ImageView.ScaleType.CENTER_CROP); background.setImageDrawable(bg); } else { background.setScaleType(ImageView.ScaleType.FIT_XY); background.setImageResource(R.drawable.app_background_tile); } processArguments(savedInstanceState); initAttachmentView(); }
From source file:com.microsoft.live.sample.skydrive.SkyDriveActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.skydrive);/*from w ww . j av a 2s. c om*/ mPrevFolderIds = new Stack<String>(); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SkyDriveObject skyDriveObj = (SkyDriveObject) parent.getItemAtPosition(position); skyDriveObj.accept(new Visitor() { @Override public void visit(SkyDriveAlbum album) { mPrevFolderIds.push(mCurrentFolderId); loadFolder(album.getId()); } @Override public void visit(SkyDrivePhoto photo) { ViewPhotoDialog dialog = new ViewPhotoDialog(SkyDriveActivity.this, photo); dialog.setOwnerActivity(SkyDriveActivity.this); dialog.show(); } @Override public void visit(SkyDriveFolder folder) { mPrevFolderIds.push(mCurrentFolderId); loadFolder(folder.getId()); } @Override public void visit(SkyDriveFile file) { Bundle b = new Bundle(); b.putString(JsonKeys.ID, file.getId()); b.putString(JsonKeys.NAME, file.getName()); showDialog(DIALOG_DOWNLOAD_ID, b); } @Override public void visit(SkyDriveVideo video) { PlayVideoDialog dialog = new PlayVideoDialog(SkyDriveActivity.this, video); dialog.setOwnerActivity(SkyDriveActivity.this); dialog.show(); } @Override public void visit(SkyDriveAudio audio) { PlayAudioDialog audioDialog = new PlayAudioDialog(SkyDriveActivity.this, audio); audioDialog.show(); } }); } }); LinearLayout layout = new LinearLayout(this); Button newFolderButton = new Button(this); newFolderButton.setText("New Folder"); newFolderButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { NewFolderDialog dialog = new NewFolderDialog(SkyDriveActivity.this); dialog.setOwnerActivity(SkyDriveActivity.this); dialog.show(); } }); layout.addView(newFolderButton); Button uploadFileButton = new Button(this); uploadFileButton.setText("Upload File"); uploadFileButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), FilePicker.class); startActivityForResult(intent, FilePicker.PICK_FILE_REQUEST); } }); layout.addView(uploadFileButton); lv.addHeaderView(layout); mPhotoAdapter = new SkyDriveListAdapter(this); setListAdapter(mPhotoAdapter); LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication(); mClient = app.getConnectClient(); }
From source file:ch.blinkenlights.android.vanilla.LibraryPagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { int type = mTabOrder[position]; ListView view = mLists[type]; if (view == null) { LibraryActivity activity = mActivity; LayoutInflater inflater = activity.getLayoutInflater(); LibraryAdapter adapter;/*ww w . ja va2 s . com*/ DraggableRow header = null; switch (type) { case MediaUtils.TYPE_ARTIST: adapter = mArtistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ARTIST, mPendingArtistLimiter, activity); mArtistAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1 || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1); header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_ALBARTIST: adapter = mAlbArtAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBARTIST, mPendingAlbArtLimiter, activity); mAlbArtAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1 || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1); header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_COMPOSER: adapter = mComposerAdapter = new MediaAdapter(activity, MediaUtils.TYPE_COMPOSER, mPendingComposerLimiter, activity); mComposerAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1 || getMediaTypePosition(MediaUtils.TYPE_ALBUM) != -1); header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_ALBUM: adapter = mAlbumAdapter = new MediaAdapter(activity, MediaUtils.TYPE_ALBUM, mPendingAlbumLimiter, activity); mAlbumAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1); mPendingAlbumLimiter = null; header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_SONG: adapter = mSongAdapter = new MediaAdapter(activity, MediaUtils.TYPE_SONG, mPendingSongLimiter, activity); mPendingSongLimiter = null; header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; case MediaUtils.TYPE_PLAYLIST: adapter = mPlaylistAdapter = new MediaAdapter(activity, MediaUtils.TYPE_PLAYLIST, null, activity); break; case MediaUtils.TYPE_GENRE: adapter = mGenreAdapter = new MediaAdapter(activity, MediaUtils.TYPE_GENRE, null, activity); mGenreAdapter.setExpandable(getMediaTypePosition(MediaUtils.TYPE_SONG) != -1); break; case MediaUtils.TYPE_FILE: adapter = mFilesAdapter = new FileSystemAdapter(activity, mPendingFileLimiter); mPendingFileLimiter = null; header = (DraggableRow) inflater.inflate(R.layout.draggable_row, null); break; default: throw new IllegalArgumentException("Invalid media type: " + type); } view = (ListView) inflater.inflate(R.layout.listview, null); view.setOnCreateContextMenuListener(this); view.setOnItemClickListener(this); view.setTag(type); if (header != null) { header.setText(mHeaderText); header.setTag(new ViewHolder()); // behave like a normal library row view.addHeaderView(header); mHeaderViews.add(header); } view.setAdapter(adapter); loadSortOrder((SortableAdapter) adapter); adapter.setFilter(mFilter); mAdapters[type] = adapter; mLists[type] = view; mRequeryNeeded[type] = true; } requeryIfNeeded(type); container.addView(view); return view; }