android.widget.ListView#post ( )源码实例Demo

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

@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);
        }
    });
}
 
源代码2 项目: Musicoco   文件: OptionsDialog.java
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());
}
 
源代码3 项目: VCL-Android   文件: AudioBrowserFragment.java
@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);
        }
    });
}
 
源代码4 项目: BotLibre   文件: ChatActivity.java
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;
}
 
源代码5 项目: BotLibre   文件: ChatActivity.java
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;
}
 
源代码6 项目: BotLibre   文件: ChatActivity.java
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;
}
 
源代码7 项目: BotLibre   文件: ChatActivity.java
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;
}
 
源代码8 项目: MCPDict   文件: FavoriteCursorAdapter.java
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);
        }
    });
}
 
源代码9 项目: microMathematics   文件: FileListView.java
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;
}
 
源代码10 项目: meatspace-android   文件: UIUtils.java
/**
 * 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);
        }
    });
}
 
源代码11 项目: NIM_Android_UIKit   文件: ListViewUtil.java
@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();
            }
        }
    });
}
 
源代码12 项目: Dashchan   文件: ViewUnit.java
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;
	}
}
 
源代码13 项目: Dashchan   文件: ThreadsPage.java
public void apply() {
	ListView listView = getListView();
	listView.removeCallbacks(this);
	listPosition = null;
	positionInfo = null;
	if (listView.getWidth() > 0) {
		run();
	} else {
		listView.post(this);
	}
}
 
源代码14 项目: Dashchan   文件: ThreadsPage.java
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);
	}
}
 
源代码15 项目: Dashchan   文件: ListPosition.java
public void apply(final ListView listView) {
	if (listView.getHeight() == 0) {
		listView.post(() -> listView.setSelectionFromTop(position, y));
	} else {
		listView.setSelectionFromTop(position, y);
	}
}
 
源代码16 项目: rss   文件: ListFragmentFavourites.java
@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()));
}
 
源代码17 项目: Android-Commons   文件: UI.java
/**
 * 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);
        	}
        }
    });
}
 
源代码18 项目: onpc   文件: MediaFragment.java
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));
}
 
源代码19 项目: BlackList   文件: InformationFragment.java
@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);
        }
    });
}
 
源代码20 项目: Kernel-Tuner   文件: FMActivity.java
@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));
	}
   }