Java Code Examples for android.widget.ListView#post()

The following examples show how to use android.widget.ListView#post() . 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: LawnAndGardenMoreListFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override public void onResume() {
    super.onResume();
    View rootView = getView();
    if (rootView == null) {
        return; // onCreate returned null
    }

    listView = (ListView) rootView.findViewById(android.R.id.list);
    listView.setDivider(null);
    listener = LawnAndGardenDeviceMoreController.instance().setCallback(this);

    listView.post(new Runnable() {
        @Override
        public void run() {
            listView.setSelection(scrollPosition);
        }
    });
}
 
Example 2
Source File: OptionsDialog.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
public OptionsDialog(Activity activity) {
    this.activity = activity;
    this.mDialog = new Dialog(activity, R.style.BottomDialog);

    mDialog.getWindow().setGravity(Gravity.BOTTOM);
    mDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
    mDialog.setCanceledOnTouchOutside(true);

    View view = LayoutInflater.from(activity).inflate(R.layout.options_container, null);
    listView = (ListView) view.findViewById(R.id.options_list);

    contentView = (LinearLayout) view.findViewById(R.id.options_container);

    titleText = (TextView) view.findViewById(R.id.options_title);
    divide = view.findViewById(R.id.options_divide);
    mDialog.setContentView(view);
    listView.post(new Runnable() {
        @Override
        public void run() {
            setDialogHeight();
        }
    });

    Utils.hideNavAndStatus(mDialog.getWindow().getDecorView());
}
 
Example 3
Source File: FavoriteCursorAdapter.java    From MCPDict with MIT License 6 votes vote down vote up
public static void scrollListToShowItem(final ListView list, final View view) {
    list.post(new Runnable() {
        @Override
        public void run() {
            int top = view.getTop();
            int bottom = view.getBottom();
            int height = bottom - top;
            int listTop = list.getPaddingTop();
            int listBottom = list.getHeight() - list.getPaddingBottom();
            int listHeight = listBottom - listTop;
            int y = (height > listHeight || bottom > listBottom) ? (listBottom - height) :
                    (top < listTop) ? listTop : top;
            int position = list.getPositionForView(view);
            list.setSelectionFromTop(position, y);
        }
    });
}
 
Example 4
Source File: ChatActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public void debug(final String text) {
	if (!DEBUG) {
		return;
	}
	final ListView list = (ListView) findViewById(R.id.chatList);
	list.post(new Runnable() {
		@Override
		public void run() {
			ChatResponse ready = new ChatResponse();
			ready.message = text;
			messages.add(ready);
			((ChatListAdapter)list.getAdapter()).notifyDataSetChanged();
			list.invalidateViews();
			if (list.getCount() > 2) {
				list.setSelection(list.getCount() - 2);
			}
		}
	});
	return;
}
 
Example 5
Source File: ChatActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public static void debug(final String text) {
	if (!DEBUG) {
		return;
	}
	final ListView list = (ListView) activity.findViewById(R.id.chatList);
	list.post(new Runnable() {
		@Override
		public void run() {
			ChatResponse ready = new ChatResponse();
			ready.message = text;
			messages.add(ready);
			((ChatListAdapter)list.getAdapter()).notifyDataSetChanged();
			list.invalidateViews();
			if (list.getCount() > 2) {
				list.setSelection(list.getCount() - 2);
			}
		}
	});
	return;
}
 
Example 6
Source File: AudioBrowserFragment.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    mMainActivity = (MainActivity) getActivity();
    if (mMediaLibrary.isWorking())
        mHandler.sendEmptyMessageDelayed(MSG_LOADING, 300);
    else if (mGenresAdapter.isEmpty() || mArtistsAdapter.isEmpty() ||
            mAlbumsAdapter.isEmpty() || mSongsAdapter.isEmpty())
        updateLists();
    else {
        updateEmptyView(mViewPager.getCurrentItem());
        focusHelper(false, mLists.get(mViewPager.getCurrentItem()).getId());
    }
    mMediaLibrary.addUpdateHandler(mHandler);
    mMediaLibrary.setBrowser(this);
    final ListView current = (ListView)mLists.get(mViewPager.getCurrentItem());
    current.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setEnabled(current.getFirstVisiblePosition() == 0);
        }
    });
}
 
Example 7
Source File: ChatActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public static void debug(final String text) {
	if (!DEBUG) {
		return;
	}
	final ListView list = (ListView) activity.findViewById(R.id.chatList);
	list.post(new Runnable() {
		@Override
		public void run() {
			ChatResponse ready = new ChatResponse();
			ready.message = text;
			messages.add(ready);
			((ChatListAdapter)list.getAdapter()).notifyDataSetChanged();
			list.invalidateViews();
			if (list.getCount() > 2) {
				list.setSelection(list.getCount() - 2);
			}
		}
	});
	return;
}
 
Example 8
Source File: ChatActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public void debug(final String text) {
	if (!DEBUG) {
		return;
	}
	final ListView list = (ListView) findViewById(R.id.chatList);
	list.post(new Runnable() {
		@Override
		public void run() {
			ChatResponse ready = new ChatResponse();
			ready.message = text;
			messages.add(ready);
			((ChatListAdapter)list.getAdapter()).notifyDataSetChanged();
			list.invalidateViews();
			if (list.getCount() > 2) {
				list.setSelection(list.getCount() - 2);
			}
		}
	});
	return;
}
 
Example 9
Source File: ListFragmentFavourites.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
@Override
public
void onActivityCreated(Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);

    ListView listView = getListView();

    registerForContextMenu(listView);
    listView.post(new LoadFavourites());
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiModeListenerFavourites(listView, getResources()));
}
 
Example 10
Source File: ListPosition.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public void apply(final ListView listView) {
	if (listView.getHeight() == 0) {
		listView.post(() -> listView.setSelectionFromTop(position, y));
	} else {
		listView.setSelectionFromTop(position, y);
	}
}
 
Example 11
Source File: ThreadsPage.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public void onListLayout(int width) {
	if (currentWidth != width) {
		currentWidth = width;
		ListView listView = getListView();
		listView.removeCallbacks(this);
		boolean gridMode = getAdapter().isGridMode();
		listPosition = gridMode ? ListPosition.obtain(listView) : null;
		positionInfo = gridMode ? getAdapter().getPositionInfo(listPosition.position) : null;
		listView.post(this);
	}
}
 
Example 12
Source File: ThreadsPage.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public void apply() {
	ListView listView = getListView();
	listView.removeCallbacks(this);
	listPosition = null;
	positionInfo = null;
	if (listView.getWidth() > 0) {
		run();
	} else {
		listView.post(this);
	}
}
 
Example 13
Source File: ViewUnit.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
boolean handlePostForDoubleClick(final View view) {
	final PostViewHolder holder = ListViewUtils.getViewHolder(view, PostViewHolder.class);
	if (holder != null) {
		if (holder.comment.getVisibility() != View.VISIBLE || holder.comment.isSelectionEnabled()) {
			return false;
		}
		long t = System.currentTimeMillis();
		long timeout = holder.comment.getPreferredDoubleTapTimeout();
		if (t - holder.lastCommentClick > timeout) {
			holder.lastCommentClick = t;
		} else {
			final ListView listView = (ListView) view.getParent();
			final int position = listView.getPositionForView(view);
			holder.comment.startSelection();
			int padding = holder.comment.getSelectionPadding();
			if (padding > 0) {
				final int listHeight = listView.getHeight() - listView.getPaddingTop() -
						listView.getPaddingBottom();
				listView.post(() -> {
					int end = holder.comment.getSelectionEnd();
					if (end >= 0) {
						Layout layout = holder.comment.getLayout();
						int line = layout.getLineForOffset(end);
						int count = layout.getLineCount();
						if (count - line <= 4) {
							listView.setSelectionFromTop(position, listHeight - view.getHeight());
						}
					}
				});
			}
		}
		return true;
	} else {
		return false;
	}
}
 
Example 14
Source File: ListViewUtil.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void scrollToPosition(final ListView messageListView, final int position, final int y, final ScrollToPositionListener listener) {
    messageListView.post(new Runnable() {

        @Override
        public void run() {
            messageListView.setSelectionFromTop(position, y);

            if (listener != null) {
                listener.onScrollEnd();
            }
        }
    });
}
 
Example 15
Source File: UIUtils.java    From meatspace-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * scroll to bottom a listview without animation
 *
 * @param listView listview to scroll
 * @param adapter associated adapter
 */
public static void scrollToBottom(final ListView listView, final Adapter adapter) {
    listView.post(new Runnable() {
        @Override
        public void run() {
            listView.setSelection(adapter.getCount() - 1);
        }
    });
}
 
Example 16
Source File: FileListView.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
public final void setSelection(int i, int y_)
{
    final ListView flv$ = listView;
    final int position$ = i, y$ = y_;
    flv$.post(new Runnable()
    {
        public void run()
        {
            flv$.setSelectionFromTop(position$, y$ > 0 ? y$ : flv$.getHeight() / 2);
        }
    });
    currentPosition = i;
}
 
Example 17
Source File: UI.java    From Android-Commons with Apache License 2.0 5 votes vote down vote up
/**
 * Scrolls to the bottom of the specified `ListView` component
 *
 * @param listView the `ListView` component
 */
public static void scrollToBottom(final ListView listView) {
	listView.post(new Runnable() {
        @Override
        public void run() {
        	final int itemCount = listView.getAdapter().getCount();

        	if (itemCount > 0) {
        		listView.setSelection(itemCount - 1);
        	}
        }
    });
}
 
Example 18
Source File: FMActivity.java    From Kernel-Tuner with GNU General Public License v3.0 4 votes vote down vote up
@Override
   public void onCreate(Bundle savedInstanceState)
{
	//supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
       super.onCreate(savedInstanceState);

	setContentView(R.layout.fm);
	fListView = (ListView) findViewById(R.id.list);

	path = savedInstanceState != null ? savedInstanceState.getString(CURR_DIR) : FILE_SEPARATOR;//Environment.getExternalStorageDirectory().toString();

       fListView.setDrawingCacheEnabled(true);
	fAdapter = new FMAdapter(this, R.layout.fm_row);

	fListView.setAdapter(fAdapter);

	ls(path, false);

	getSupportActionBar().setSubtitle(path);
	fListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
	{
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
									long arg3)
			{
                   FMEntry entry = fAdapter.getItem(pos);
                   if(entry.getType() == TYPE_DIRECTORY || entry.getType() == TYPE_DIRECTORY_LINK)
                   {
                       Parcelable state = fListView.onSaveInstanceState();
                       listScrollStates.put(path, state);
                       backstack.add(path);
                       path = entry.getType() == TYPE_DIRECTORY_LINK ? entry.getLink() : entry.getPath();
                       validatePath();
                       ls(path, false);
                   }
                   else if(entry.getType() == TYPE_FILE || entry.getType() == TYPE_LINK)
                   {
                       //TODO
                   }
			}
		});
	if(savedInstanceState != null)
	{
           backstack = (LinkedList<String>) savedInstanceState.getSerializable(BACKSTACK);
		Parcelable listState = savedInstanceState.getParcelable("list_position");
		if(listState != null)fListView.post(new RestoreListStateRunnable(listState));
	}
   }
 
Example 19
Source File: InformationFragment.java    From BlackList with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    listView = (ListView) view.findViewById(R.id.help_list);

    InformationArrayAdapter adapter = new InformationArrayAdapter(getContext());

    adapter.addTitle(R.string.About);
    String title = getString(R.string.app_name) + " (" + getAppVersion() + ")";
    adapter.addText(title, getString(R.string.Info_about));

    adapter.addTitle(R.string.Attention);
    adapter.addText(R.string.Info_attention);

    adapter.addTitle(R.string.Messaging);
    adapter.addText(R.string.Info_messaging);

    adapter.addTitle(R.string.Black_list);
    adapter.addText(R.string.Info_black_list);

    adapter.addTitle(R.string.White_list);
    adapter.addText(R.string.Info_white_list);

    adapter.addTitle(R.string.Journal);
    adapter.addText(R.string.Info_journal);

    adapter.addTitle(R.string.Settings);
    adapter.addText(R.string.Info_settings);

    adapter.addTitle(R.string.Licence);
    adapter.addText(R.string.Info_licence);

    adapter.addTitle(R.string.Author);
    adapter.addText(R.string.Info_author);

    // add adapter to the ListView and scroll list to position
    listView.setAdapter(adapter);
    listView.post(new Runnable() {
        @Override
        public void run() {
            listView.setSelection(listPosition);
        }
    });
}
 
Example 20
Source File: MediaFragment.java    From onpc with GNU General Public License v3.0 4 votes vote down vote up
private void setSelection(int i, int y_)
{
    final ListView flv$ = listView;
    final int position$ = i, y$ = y_;
    flv$.post(() -> flv$.setSelectionFromTop(position$, y$ > 0 ? y$ : flv$.getHeight() / 2));
}