android.widget.Adapter#getItem ( )源码实例Demo

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

源代码1 项目: YiBo   文件: MicroBlogContextMenuListener.java
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
		ContextMenuInfo menuInfo) {
	final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
	Adapter adapter = lvMicroBlog.getAdapter();
	this.position = info.position;
	targetView = info.targetView;
	Status status= (Status)adapter.getItem(position);
	if (status == null 
		|| (status instanceof LocalStatus
			&& ((LocalStatus)status).isDivider())) {
		return;
	}

	Context context = v.getContext();
	analyzeStatusMenu(adapter, status, menu, context);
}
 
源代码2 项目: open-rmbt   文件: SectionListAdapter.java
@Override
public Object getItem(int position)
{
    
    for (final Map.Entry<String,Adapter> entry : sectionMap.entrySet())
    {
        final Adapter adapter = entry.getValue();
        
        final int size = adapter.getCount() + (hasSectionHeader ? 1 : 0);
        
        if (position == 0 && hasSectionHeader)
            return entry.getKey();
        
        if (position < size)
            return adapter.getItem(position - 1);
        
        position -= size;
    }
    
    return null;
}
 
@Override
public void onItemSelected(AdapterView<?> parent, View view,
		int position, long id) {
	Adapter adapter = parent.getAdapter();
	Authorization auth = context.getAuth();
	if (auth == null) {
		Logger.error("auth can't be null");
		return;
	}
	
	ConfigApp configApp = (ConfigApp)adapter.getItem(position);		
	if (configApp.getAppId() == -2l) {
		Intent intent = new Intent();
		intent.setClass(context, AddConfigAppActivity.class);
		intent.putExtra("spNo", auth.getServiceProvider().getSpNo());
		context.startActivityForResult(intent, Constants.REQUEST_CODE_CONFIG_APP_ADD);
		return;
	}
	
	OAuthConfig oauthConfig = auth.getoAuthConfig();
	oauthConfig.setConsumerKey(configApp.getAppKey());
	oauthConfig.setConsumerSecret(configApp.getAppSecret());
	oauthConfig.setCallbackUrl(configApp.getCallbackUrl());
	Logger.debug("callback:{}", oauthConfig.getCallbackUrl());
}
 
public Object getItem(int position)
{
    for(String section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if(position == 0)
            return section;
        if(position < size)
            return adapter.getItem(position - 1);

        // otherwise jump into next section
        position -= size;
    }
    return null;
}
 
源代码5 项目: shortyz   文件: SeparatedListAdapter.java
public Object getItem(int position) {
    int section = 0;

    for (Adapter adapter : this.sections) {
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position == 0) {
            return headers.getItem(section);
        }

        if (position < size) {
            return adapter.getItem(position - 1);
        }

        // otherwise jump into next section
        position -= size;
        section++;
    }

    return null;
}
 
源代码6 项目: Lynx   文件: LynxActivityTest.java
private static Matcher<View> withTraceLevelInAdapter(final TraceLevel traceLevel) {
  return new TypeSafeMatcher<View>() {

    @Override public void describeTo(Description description) {
      description.appendText(
          "Your ListView contains at least one trace with TraceLevel less than TraceLevel: ");
      description.appendText(String.valueOf(traceLevel));
    }

    @Override public boolean matchesSafely(View view) {
      if (!(view instanceof AdapterView)) {
        return false;
      }
      @SuppressWarnings("rawtypes") Adapter adapter = ((AdapterView) view).getAdapter();
      for (int i = 0; i < adapter.getCount(); i++) {
        Trace trace = (Trace) adapter.getItem(i);
        if (trace.getLevel().ordinal() < traceLevel.ordinal()) {
          return true;
        }
      }
      return false;
    }
  };
}
 
源代码7 项目: YiBo   文件: CommentsItemClickListener.java
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
		long id) {
	Adapter adapter = parent.getAdapter();
       comment = (Comment)adapter.getItem(position);
       if (comment == null
       	|| (comment instanceof LocalComment
       		&& ((LocalComment)comment).isDivider())) {
       	return;
       }

       if (adapter instanceof HeaderViewListAdapter) {
       	adapter = ((HeaderViewListAdapter)adapter).getWrappedAdapter();
       }
       CacheAdapter<Comment> cacheAdapter = (CacheAdapter<Comment>)adapter;

       Dialog dialog = onCreateDialog(cacheAdapter, position);
       if (dialog != null) {
       	dialog.show();
       }
}
 
源代码8 项目: BatteryFu   文件: SeparatedListAdapter.java
@Override
public Object getItem(int position) {
    for (int i = 0; i < headers.getCount(); i++) {
        String section = headers.getItem(i);
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position == 0)
            return section;
        if (position < size)
            return adapter.getItem(position - 1);

        // otherwise jump into next section
        position -= size;
    }
    return null;
}
 
源代码9 项目: YiBo   文件: ConversationItemClickListener.java
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
		long id) {
	Adapter adapter = parent.getAdapter();
	message = (DirectMessage)adapter.getItem(position);
       if (message == null 
       	|| (message instanceof LocalDirectMessage
       		&& ((LocalDirectMessage)message).isDivider())) {
       	return;
       }

       if (adapter instanceof HeaderViewListAdapter) {
       	adapter = ((HeaderViewListAdapter)adapter).getWrappedAdapter();
       }
	CacheAdapter<DirectMessage> cacheAdapter = (CacheAdapter<DirectMessage>)adapter;

       Dialog dialog = onCreateDialog(cacheAdapter, position);
       if (dialog != null) {
       	dialog.show();
       }
}
 
源代码10 项目: YiBo   文件: DirectMessagesItemClickListener.java
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
		long id) {
	Adapter adapter = parent.getAdapter();
	message = (DirectMessage)adapter.getItem(position);
       if (message == null 
       	|| (message instanceof LocalDirectMessage
       		&& ((LocalDirectMessage)message).isDivider())) {
       	return;
       }

       if (adapter instanceof HeaderViewListAdapter) {
       	adapter = ((HeaderViewListAdapter)adapter).getWrappedAdapter();
       }
	CacheAdapter<DirectMessage> cacheAdapter = (CacheAdapter<DirectMessage>)adapter;

       Dialog dialog = onCreateDialog(cacheAdapter, position);
       if (dialog != null) {
       	dialog.show();
       }
}
 
源代码11 项目: SSForms   文件: StarkSpinner.java
public Object getSelectedItem() {
    if (mCurrSelectedView != null) {
        int position = mCurrSelectedView.getPosition();
        Adapter adapter = mSpinnerListView.getAdapter();
        if (adapter != null && adapter.getCount() > 0 && position >= 0) {
            return adapter.getItem(position);
        } else {
            return null;
        }
    }
    return null;
}
 
源代码12 项目: searchablespinner   文件: SearchableSpinner.java
public Object getSelectedItem() {
    if (mCurrSelectedView != null) {
        int position = mCurrSelectedView.getPosition();
        Adapter adapter = mSpinnerListView.getAdapter();
        if (adapter != null && adapter.getCount() > 0 && position >= 0) {
            return adapter.getItem(position);
        } else {
            return null;
        }
    }
    return null;
}
 
源代码13 项目: searchablespinner   文件: SearchableSpinner.java
public int getItemPosition(Object item) {
    if (item == null)
        return -1;
    Adapter adapter = mSpinnerListView.getAdapter();
    if (adapter != null) {
        for (int i = 0; i < adapter.getCount(); i++) {
            Object adpItem = adapter.getItem(i);
            if (adpItem != null && adpItem.equals(item)) {
                return i;
            }
        }
    }
    return -1;
}
 
private String getContentString(){
    StringBuilder content = new StringBuilder();
    Adapter a = lvItemList.getAdapter();
    CheckListItem temp;
    for (int i=0; i < itemNamesList.size(); i++) {
        temp = (CheckListItem) a.getItem(i);
        content.append("- " + temp.getName() + " [" + (temp.isChecked() ? "✓" : "   ") + "]\n");
    }
    return content.toString();
}
 
源代码15 项目: RoMote   文件: SeparatedListAdapter.java
public Object getItem(int position) {
    for(Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if(position == 0) return section;
        if(position < size) return adapter.getItem(position - 1);

        // otherwise jump into next section
        position -= size;
    }
    return null;
}
 
源代码16 项目: padland   文件: SeparatedListAdapter.java
public Object getItem(int position) {
    for(Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if(position == 0) return section;
        if(position < size) return adapter.getItem(position - 1);

        // otherwise jump into next section
        position -= size;
    }
    return null;
}
 
源代码17 项目: android-tv-launcher   文件: AdapterView.java
public Object getSelectedItem() {
	Adapter localAdapter = getAdapter();
	int i = getSelectedItemPosition();
	if ((localAdapter != null) && (localAdapter.getCount() > 0) && (i >= 0))
		return localAdapter.getItem(i);
	return null;
}
 
public Object getItem(int position) {
    for (Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;
        // check if position inside this section
        if (position == 0)
            return section;
        if (position < size)
            return adapter.getItem(position - 1);
        // otherwise jump into next section
        position -= size;
    }
    return null;
}
 
源代码19 项目: rss   文件: ListViewFeeds.java
@Override
public
void onScrollStateChanged(AbsListView view, int scrollState)
{
    FeedsActivity activity = (FeedsActivity) view.getContext();

    if(SCROLL_STATE_TOUCH_SCROLL == scrollState || SCROLL_STATE_IDLE == scrollState)
    {
        Adapter adapter = view.getAdapter();
        int first = view.getFirstVisiblePosition();
        int last = view.getLastVisiblePosition();

        for(int i = 0; last - first >= i; i++)
        {
            View viewItem = view.getChildAt(i);

            if(null != viewItem && viewItem.isShown() && 0 <= viewItem.getTop())
            {
                FeedItem item = (FeedItem) adapter.getItem(first + i);
                activity.readItem(item.m_time);
            }
        }
    }
    if(SCROLL_STATE_IDLE == scrollState)
    {
        AsyncNavigationAdapter.run(activity);
    }
}
 
源代码20 项目: YiBo   文件: MicroBlogItemClickListener.java
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
		long id) {
	Adapter adapter = parent.getAdapter();
       Status status = (Status)adapter.getItem(position);
	if (status == null 
		|| (status instanceof LocalStatus
			&& ((LocalStatus)status).isDivider())) {
		return;
	}
	
	Intent intent = new Intent();
	Bundle bundle = new Bundle();

	bundle.putSerializable("STATUS", status);
	CacheAdapter<?> cacheAdapter = AdapterUtil.getCacheAdapter(adapter);
	if (cacheAdapter instanceof MyHomeListAdapter) {
		bundle.putInt("SOURCE", Constants.REQUEST_CODE_MY_HOME);
		bundle.putInt("POSITION", position - 1);
	}
	intent.putExtras(bundle);

	intent.setClass(parent.getContext(), MicroBlogActivity.class);
	((Activity)context).startActivityForResult(intent, Constants.REQUEST_CODE_MICRO_BLOG);
	CompatibilityUtil.overridePendingTransition(
		(Activity)context, R.anim.slide_in_right, android.R.anim.fade_out
	);
}