Java Code Examples for android.widget.Adapter#getItem()

The following examples show how to use android.widget.Adapter#getItem() . 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: LynxActivityTest.java    From Lynx with Apache License 2.0 6 votes vote down vote up
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;
    }
  };
}
 
Example 2
Source File: DirectMessagesItemClickListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@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();
       }
}
 
Example 3
Source File: ConversationItemClickListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@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();
       }
}
 
Example 4
Source File: SeparatedListAdapter.java    From BatteryFu with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: CommentsItemClickListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@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();
       }
}
 
Example 6
Source File: SeparatedListAdapter.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: SeparatedListAdapter.java    From sensordatacollector with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 8
Source File: AddAccountConfigAppItemSelectedListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 9
Source File: SectionListAdapter.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 10
Source File: MicroBlogContextMenuListener.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 11
Source File: SeparatedListAdapter.java    From RoMote with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 13
Source File: StarkSpinner.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: SeparatedListAdapter.java    From padland with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 15
Source File: AdapterView.java    From android-tv-launcher with MIT License 5 votes vote down vote up
public Object getSelectedItem() {
	Adapter localAdapter = getAdapter();
	int i = getSelectedItemPosition();
	if ((localAdapter != null) && (localAdapter.getCount() > 0) && (i >= 0))
		return localAdapter.getItem(i);
	return null;
}
 
Example 16
Source File: SeparatedListAdapter.java    From Makeblock-App-For-Android with MIT License 5 votes vote down vote up
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;
}
 
Example 17
Source File: ListViewFeeds.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 18
Source File: SearchableSpinner.java    From searchablespinner with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 19
Source File: SearchableSpinner.java    From searchablespinner with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 20
Source File: MicroBlogItemClickListener.java    From YiBo with Apache License 2.0 5 votes vote down vote up
@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
	);
}