本文整理汇总了Java中android.util.SparseArray.put方法的典型用法代码示例。如果您正苦于以下问题:Java SparseArray.put方法的具体用法?Java SparseArray.put怎么用?Java SparseArray.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.SparseArray
的用法示例。
在下文中一共展示了SparseArray.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getView
import android.util.SparseArray; //导入方法依赖的package包/类
/**
* findViewById
* @param rootView
* @param viewId
* @param <T>
* @return
*/
public static <T extends View> T getView(View rootView, int viewId) {
SparseArray<View> views = null;
Object tag = rootView.getTag();
if (tag != null && tag instanceof SparseArray) {
views = (SparseArray<View>)tag;
}
if(views == null){
views = new SparseArray<>();
rootView.setTag(views);
}
View view = views.get(viewId);
if (view == null) {
view = rootView.findViewById(viewId);
views.put(viewId, view);
}
return (T) view;
}
示例2: ensureCachedScrollSelectorValue
import android.util.SparseArray; //导入方法依赖的package包/类
/**
* Ensures we have a cached string representation of the given <code>
* selectorIndex</code> to avoid multiple instantiations of the same string.
*/
private void ensureCachedScrollSelectorValue(int selectorIndex) {
SparseArray<String> cache = mSelectorIndexToStringCache;
String scrollSelectorValue = cache.get(selectorIndex);
if (scrollSelectorValue != null) {
return;
}
if (selectorIndex < mMinValue || selectorIndex > mMaxValue) {
scrollSelectorValue = "";
} else {
if (mDisplayedValues != null) {
int displayedValueIndex = selectorIndex - mMinValue;
scrollSelectorValue = mDisplayedValues[displayedValueIndex];
} else {
scrollSelectorValue = formatNumber(selectorIndex);
}
}
cache.put(selectorIndex, scrollSelectorValue);
}
示例3: hold
import android.util.SparseArray; //导入方法依赖的package包/类
/**
* ViewHolder简洁写法,避免适配器中重复定义ViewHolder,减少代码量 用法:
*
* <pre>
* if (convertView == null)
* {
* convertView = View.inflate(context, R.layout.ad_demo, null);
* }
* TextView tv_demo = ViewHolderUtils.get(convertView, R.id.tv_demo);
* ImageView iv_demo = ViewHolderUtils.get(convertView, R.id.iv_demo);
* </pre>
*/
public static <T extends View> T hold(View view, int id)
{
SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
if (viewHolder == null)
{
viewHolder = new SparseArray<View>();
view.setTag(viewHolder);
}
View childView = viewHolder.get(id);
if (childView == null)
{
childView = view.findViewById(id);
viewHolder.put(id, childView);
}
return (T) childView;
}
示例4: addAndGetModel
import android.util.SparseArray; //导入方法依赖的package包/类
private synchronized Listener4Model addAndGetModel(BreakpointInfo info) {
SparseArray<Long> blockCurrentOffsetMap = new SparseArray<>();
final int blockCount = info.getBlockCount();
for (int i = 0; i < blockCount; i++) {
final BlockInfo blockInfo = info.getBlock(i);
blockCurrentOffsetMap.put(i, blockInfo.getCurrentOffset());
}
Listener4Model model = new Listener4Model(info, info.getTotalOffset(),
blockCurrentOffsetMap);
if (assistExtend != null) model = assistExtend.inspectAddModel(model);
if (singleTaskModel == null || singleTaskModel.info.getId() == info.getId()) {
singleTaskModel = model;
} else {
modelList.put(info.getId(), model);
}
return model;
}
示例5: getIMAddressesMap
import android.util.SparseArray; //导入方法依赖的package包/类
private SparseArray<List<IMAddress>> getIMAddressesMap() {
SparseArray<List<IMAddress>> idImAddressMap = new SparseArray<>();
Cursor cur = getCursorFromContentType(new String[]{ID_KEY, MAIN_DATA_KEY, Im.PROTOCOL, Im.CUSTOM_PROTOCOL}, Im.CONTENT_ITEM_TYPE);
if (cur != null) {
while (cur.moveToNext()) {
int id = cur.getInt(cur.getColumnIndex(ID_KEY));
String data = cur.getString(cur.getColumnIndex(MAIN_DATA_KEY));
int labelId = cur.getInt(cur.getColumnIndex(Im.PROTOCOL));
String customLabel = cur.getString(cur.getColumnIndex(Im.CUSTOM_PROTOCOL));
IMAddress current;
if (customLabel == null)
current = new IMAddress(mCtx, data, labelId);
else
current = new IMAddress(data, customLabel);
List<IMAddress> currentWebsiteList = idImAddressMap.get(id);
if (currentWebsiteList == null) {
currentWebsiteList = new ArrayList<>();
currentWebsiteList.add(current);
idImAddressMap.put(id, currentWebsiteList);
} else currentWebsiteList.add(current);
}
cur.close();
}
return idImAddressMap;
}
示例6: showFab
import android.util.SparseArray; //导入方法依赖的package包/类
private void showFab(int tabPosition) {
SparseArray<FloatingActionButton> positionToFab = new SparseArray<>();
positionToFab.put(1, addArtistFab);
positionToFab.put(2, addLocationFab);
ScreenUtils.remainRightFab(positionToFab.get(tabPosition, null), allFabs);
}
示例7: cleanFiles
import android.util.SparseArray; //导入方法依赖的package包/类
/**
* 将所选文件添加到清理列表中
*/
private void cleanFiles() {
ArrayList<String> _cleanPathList = new ArrayList<>(_adapter.get_checkList().size());
SparseArray<SDFile> _cleanFiles = new SparseArray<>(_adapter.get_checkList().size());
for (int _position : _adapter.get_checkList()) {
_cleanPathList.add(_adapter.get_data().get_children().get(_position).get_path());
_cleanFiles.put(_position, _adapter.get_data().get_children().get(_position));
}
Global.add_cleanList(_cleanPathList);
showProgress(ACTION_CLEAN, _cleanFiles.size());
new UpdateRubbishThread(_cleanFiles).start();
}
示例8: get
import android.util.SparseArray; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends View> T get(View view, int id) {
SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
if (viewHolder == null) {
viewHolder = new SparseArray<View>();
view.setTag(viewHolder);
}
View childView = viewHolder.get(id);
if (childView == null) {
childView = view.findViewById(id);
viewHolder.put(id, childView);
}
return (T) childView;
}
示例9: scrapActiveViews
import android.util.SparseArray; //导入方法依赖的package包/类
/**
* Move all views remaining in activeViews to scrapViews.
*/
void scrapActiveViews() {
final View[] activeViews = this.activeViews;
final int[] activeViewTypes = this.activeViewTypes;
final boolean multipleScraps = viewTypeCount > 1;
SparseArray<View> scrapViews = currentScrapViews;
final int count = activeViews.length;
for (int i = count - 1; i >= 0; i--) {
final View victim = activeViews[i];
if (victim != null) {
int whichScrap = activeViewTypes[i];
activeViews[i] = null;
activeViewTypes[i] = -1;
if (!shouldRecycleViewType(whichScrap)) {
continue;
}
if (multipleScraps) {
scrapViews = this.scrapViews[whichScrap];
}
scrapViews.put(i, victim);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
victim.setAccessibilityDelegate(null);
}
}
}
pruneScrapViews();
}
示例10: filterOutNoExist
import android.util.SparseArray; //导入方法依赖的package包/类
private synchronized void filterOutNoExist() {
SparseArray<DownloadLaunchRunnable> correctedRunnablePool = new SparseArray<>();
final int size = runnablePool.size();
for (int i = 0; i < size; i++) {
final int key = runnablePool.keyAt(i);
final DownloadLaunchRunnable runnable = runnablePool.get(key);
if (runnable.isAlive()) {
correctedRunnablePool.put(key, runnable);
}
}
runnablePool = correctedRunnablePool;
}
示例11: getLayoutIdMap
import android.util.SparseArray; //导入方法依赖的package包/类
@Override
protected SparseArray<Integer> getLayoutIdMap() {
SparseArray<Integer> result = new SparseArray<>();
result.put(Demo.TYPE_NORMAL, R.layout.demo_normal_layout);
result.put(Demo.TYPE_SPECIAL, R.layout.demo_special_layout);
return result;
}
示例12: initSkin
import android.util.SparseArray; //导入方法依赖的package包/类
/**
* Copy skin from assets.
*/
void initSkin(Context context) {
SparseArray<String> array = new SparseArray<>();
array.put(R.raw.skin_vivid, "生动皮肤");
array.put(R.raw.skin_plain, "普通皮肤");
File root = new File(SKIN_ROOT);
if (!root.exists()) {
root.mkdirs();
}
for (int i = 0; i < array.size(); i++) {
copySkinArchive(context, array.keyAt(i), SKIN_ROOT + File.separator + array.valueAt(i) + SKIN_SUFFIX);
}
}
示例13: getIncomingMessages
import android.util.SparseArray; //导入方法依赖的package包/类
SparseArray<ConversationItem> getIncomingMessages() {
SparseArray<ConversationItem> messages = new SparseArray<>();
for (int i = 0; i < items.size(); i++) {
ConversationItem item = items.get(i);
if (item.isIncoming()) {
messages.put(i, item);
}
}
return messages;
}
示例14: loadTravelersSuccess
import android.util.SparseArray; //导入方法依赖的package包/类
protected Response.Listener<JSONArray> loadTravelersSuccess() {
return new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
SparseArray<Traveler> sparseArray = new SparseArray<Traveler>();
for (int i = 0; i < response.length(); i++) {
Traveler traveler = new Traveler(
response.getJSONObject(i).getInt("id"),
response.getJSONObject(i).getString("firstName"),
response.getJSONObject(i).getString("lastName"),
response.getJSONObject(i).getString("email"),
response.getJSONObject(i).getString("uid")
);
if (traveler.getId() != currentUser.getId()) {
// Only add traveler if it's not me.
sparseArray.put(traveler.getId(), traveler);
}
}
TravelerAdapter adapter = new TravelerAdapter(sparseArray);
mListView.setAdapter(adapter);
} catch (JSONException e) {
Toast.makeText(ListPublicChatMembersActivity.this, TAG + ": " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
};
}
示例15: scrapActiveViews
import android.util.SparseArray; //导入方法依赖的package包/类
/** Move all views remaining in activeViews to scrapViews. */
void scrapActiveViews() {
final View[] activeViews = this.activeViews;
final int[] activeViewTypes = this.activeViewTypes;
final boolean multipleScraps = viewTypeCount > 1;
SparseArray<View> scrapViews = currentScrapViews;
final int count = activeViews.length;
for (int i = count - 1; i >= 0; i--) {
final View victim = activeViews[i];
if (victim != null) {
int whichScrap = activeViewTypes[i];
activeViews[i] = null;
activeViewTypes[i] = -1;
if (!shouldRecycleViewType(whichScrap)) {
continue;
}
if (multipleScraps) {
scrapViews = this.scrapViews[whichScrap];
}
scrapViews.put(i, victim);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
victim.setAccessibilityDelegate(null);
}
}
}
pruneScrapViews();
}