Java Code Examples for android.widget.Adapter

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-xbmcremote, under directory /src/org/xbmc/android/widget/.

Source file: FastScrollView.java

  22 
vote

private void getSections(){
  Adapter adapter=mList.getAdapter();
  if (adapter instanceof HeaderViewListAdapter) {
    mListOffset=((HeaderViewListAdapter)adapter).getHeadersCount();
    adapter=((HeaderViewListAdapter)adapter).getWrappedAdapter();
  }
  if (adapter instanceof SectionIndexer) {
    mListAdapter=(BaseAdapter)adapter;
    mSections=((SectionIndexer)mListAdapter).getSections();
  }
}
 

Example 2

From project androidquery, under directory /src/com/androidquery/.

Source file: AbstractAQuery.java

  22 
vote

/** 
 * Notify a ListView that the data of it's adapter is changed.
 * @return self
 */
public T dataChanged(){
  if (view instanceof AdapterView) {
    AdapterView<?> av=(AdapterView<?>)view;
    Adapter a=av.getAdapter();
    if (a instanceof BaseAdapter) {
      BaseAdapter ba=(BaseAdapter)a;
      ba.notifyDataSetChanged();
    }
  }
  return self();
}
 

Example 3

From project apps-for-android, under directory /RingsExtended/src/com/example/android/rings_extended/.

Source file: FastScrollView.java

  22 
vote

private void getSections(){
  Adapter adapter=mList.getAdapter();
  if (adapter instanceof HeaderViewListAdapter) {
    mListOffset=((HeaderViewListAdapter)adapter).getHeadersCount();
    adapter=((HeaderViewListAdapter)adapter).getWrappedAdapter();
  }
  if (adapter instanceof SectionIndexer) {
    mListAdapter=(BaseAdapter)adapter;
    mSections=((SectionIndexer)mListAdapter).getSections();
  }
}
 

Example 4

From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.

Source file: SeparatedListAdapter.java

  22 
vote

public Object getItem(int position){
  for (  Object section : this.sections.keySet()) {
    Adapter adapter=sections.get(section);
    int size=adapter.getCount() + 1;
    if (position == 0)     return section;
    if (position < size)     return adapter.getItem(position - 1);
    position-=size;
  }
  return null;
}
 

Example 5

From project jamendo-android, under directory /src/com/teleca/jamendo/adapter/.

Source file: SeparatedListAdapter.java

  22 
vote

public Object getItem(int position){
  for (  Object section : this.sections.keySet()) {
    Adapter adapter=sections.get(section);
    int size=adapter.getCount() + 1;
    if (position == 0)     return section;
    if (position < size)     return adapter.getItem(position - 1);
    position-=size;
  }
  return null;
}
 

Example 6

From project lastfm-android, under directory /app/src/fm/last/android/adapter/.

Source file: SeparatedListAdapter.java

  22 
vote

public Object getItem(int position){
  for (  Object section : this.sections.keySet()) {
    Adapter adapter=sections.get(section);
    int size=adapter.getCount() + 1;
    if (position == 0)     return section;
    if (position < size)     return adapter.getItem(position - 1);
    position-=size;
  }
  return null;
}
 

Example 7

From project Locast-Android, under directory /src/org/jsharkey/blog/android/.

Source file: SeparatedListAdapter.java

  22 
vote

public Object getItem(int position){
  for (  final SectionHeader section : this.sections) {
    final Adapter adapter=section.adapter;
    final int size=adapter.getCount() + 1;
    if (position == 0) {
      return section;
    }
    if (position < size) {
      return adapter.getItem(position - 1);
    }
    position-=size;
  }
  return null;
}
 

Example 8

From project RC4A, under directory /src/org/rubychina/android/widget/.

Source file: SeparatedListAdapter.java

  22 
vote

public Object getItem(int position){
  for (  Object section : this.sections.keySet()) {
    Adapter adapter=sections.get(section);
    int size=adapter.getCount() + 1;
    if (position == 0)     return section;
    if (position < size)     return adapter.getItem(position - 1);
    position-=size;
  }
  return null;
}
 

Example 9

From project SWADroid, under directory /SWADroid/src/es/ugr/swad/swadroid/modules/rollcall/sessions/.

Source file: SeparatedListAdapter.java

  22 
vote

@Override public Object getItem(int position){
  for (  Object section : this.sections.keySet()) {
    Adapter adapter=sections.get(section);
    int size=adapter.getCount() + 1;
    if (position == 0)     return section;
    if (position < size)     return adapter.getItem(position - 1);
    position-=size;
  }
  return null;
}
 

Example 10

From project uberdust-android, under directory /src/eu/uberdust/mobileclient/.

Source file: SeparatedListAdapter.java

  22 
vote

public Object getItem(int position){
  for (  Object section : this.sections.keySet()) {
    Adapter adapter=sections.get(section);
    int size=adapter.getCount() + 1;
    if (position == 0)     return section;
    if (position < size)     return adapter.getItem(position - 1);
    position-=size;
  }
  return null;
}
 

Example 11

From project yammp, under directory /src/org/yammp/widget/.

Source file: SeparatedListAdapter.java

  22 
vote

@Override public Object getItem(int position){
  for (  Object section : sections.keySet()) {
    Adapter adapter=sections.get(section);
    int size=adapter.getCount() + 1;
    if (position == 0)     return section;
    if (position < size)     return adapter.getItem(position - 1);
    position-=size;
  }
  return null;
}
 

Example 12

From project Android-automation, under directory /Tmts_Java/src/com/taobao/tmts/framework/view/.

Source file: TmtsAutoCompleteTextView.java

  21 
vote

/** 
 * Get the text of AutoCompleteTextView by the given index
 * @param index index we specified
 * @return text of the given index
 */
public String getAutoCompleteText(int index){
  Adapter adapter=autoCompleteTextView.getAdapter();
  int maxIndex=adapter.getCount();
  if (index < 0 || index > maxIndex - 1) {
    return null;
  }
 else {
    try {
      Thread.sleep(Constants.ANR_TIME);
    }
 catch (    InterruptedException e) {
      e.printStackTrace();
    }
    return adapter.getItem(index).toString();
  }
}
 

Example 13

From project android-pulltorefresh, under directory /library/src/com/handmark/pulltorefresh/library/.

Source file: PullToRefreshAdapterViewBase.java

  21 
vote

private boolean isFirstItemVisible(){
  final Adapter adapter=mRefreshableView.getAdapter();
  if (null == adapter || adapter.isEmpty()) {
    if (DEBUG) {
      Log.d(LOG_TAG,"isFirstItemVisible. Empty View.");
    }
    return true;
  }
 else {
    if (mRefreshableView.getFirstVisiblePosition() <= 1) {
      final View firstVisibleChild=mRefreshableView.getChildAt(0);
      if (firstVisibleChild != null) {
        return firstVisibleChild.getTop() >= mRefreshableView.getTop();
      }
    }
  }
  return false;
}
 

Example 14

From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.

Source file: FastScroller.java

  21 
vote

private void getSections(){
  Adapter adapter=mList.getAdapter();
  mSectionIndexerV1=null;
  mSectionIndexerV2=null;
  if (adapter instanceof HeaderViewListAdapter) {
    mListOffset=((HeaderViewListAdapter)adapter).getHeadersCount();
    adapter=((HeaderViewListAdapter)adapter).getWrappedAdapter();
  }
  if (mList instanceof ExpandableListView) {
    ExpandableListAdapter expAdapter=((ExpandableListView)mList).getExpandableListAdapter();
    if (expAdapter instanceof SectionIndexer) {
      mSectionIndexerV1=(SectionIndexer)expAdapter;
      mListAdapter=(BaseAdapter)adapter;
      mSections=mSectionIndexerV1.getSections();
    }
 else     if (expAdapter instanceof SectionIndexerV2) {
      mSectionIndexerV2=(SectionIndexerV2)expAdapter;
      mListAdapter=(BaseAdapter)adapter;
    }
  }
 else {
    if (adapter instanceof SectionIndexer) {
      mListAdapter=(BaseAdapter)adapter;
      mSectionIndexerV1=(SectionIndexer)adapter;
      mSections=mSectionIndexerV1.getSections();
    }
 else     if (adapter instanceof SectionIndexerV2) {
      mListAdapter=(BaseAdapter)adapter;
      mSectionIndexerV2=(SectionIndexerV2)adapter;
    }
 else {
      mListAdapter=(BaseAdapter)adapter;
      mSections=new String[]{" "};
    }
  }
}
 

Example 15

From project NotePad, under directory /src/com/nononsenseapps/ui/.

Source file: SectionAdapter.java

  21 
vote

/** 
 * Get the section a position is contained in.
 */
public String getSection(int position){
  if (headers == null) {
    throw new InvalidParameterException(ERRORMSG);
  }
  for (int headerPos=0; headerPos < headers.getCount(); headerPos++) {
    Adapter adapter=sections.get(headers.getItem(headerPos));
    if (adapter.getCount() > 0) {
      if (position == 0)       return headers.getItem(headerPos);
      position-=1;
      if (position < adapter.getCount())       return headers.getItem(headerPos);
      position-=adapter.getCount();
    }
  }
  return null;
}
 

Example 16

From project packages_apps_Calendar, under directory /src/com/android/calendar/agenda/.

Source file: AgendaFragment.java

  21 
vote

@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  View v=inflater.inflate(R.layout.agenda_fragment,null);
  mAgendaListView=(AgendaListView)v.findViewById(R.id.agenda_events_list);
  mAgendaListView.setClickable(true);
  if (savedInstanceState != null) {
    long instanceId=savedInstanceState.getLong(BUNDLE_KEY_RESTORE_INSTANCE_ID,-1);
    if (instanceId != -1) {
      mAgendaListView.setSelectedInstanceId(instanceId);
    }
  }
  if (!mShowEventDetailsWithAgenda) {
    v.findViewById(R.id.agenda_event_info).setVisibility(View.GONE);
  }
  StickyHeaderListView lv=(StickyHeaderListView)v.findViewById(R.id.agenda_sticky_header_list);
  if (lv != null) {
    Adapter a=mAgendaListView.getAdapter();
    lv.setAdapter(a);
    if (a instanceof HeaderViewListAdapter) {
      mAdapter=(AgendaWindowAdapter)((HeaderViewListAdapter)a).getWrappedAdapter();
      lv.setIndexer(mAdapter);
      lv.setHeaderHeightListener(mAdapter);
    }
 else     if (a instanceof AgendaWindowAdapter) {
      mAdapter=(AgendaWindowAdapter)a;
      lv.setIndexer(mAdapter);
      lv.setHeaderHeightListener(mAdapter);
    }
 else {
      Log.wtf(TAG,"Cannot find HeaderIndexer for StickyHeaderListView");
    }
    lv.setOnScrollListener(this);
    lv.setHeaderSeparator(getResources().getColor(R.color.agenda_list_separator_color),1);
  }
  return v;
}
 

Example 17

From project sthlmtraveling, under directory /src/com/markupartist/sthlmtraveling/.

Source file: RoutesActivity.java

  21 
vote

@Override protected void onListItemClick(ListView l,View v,int position,long id){
  super.onListItemClick(l,v,position,id);
  int headerViewsCount=getListView().getHeaderViewsCount();
  position-=headerViewsCount;
  Section section=mSectionedAdapter.getSection(position);
  int sectionId=section.id;
  int innerPosition=mSectionedAdapter.getSectionIndex(position);
  Adapter adapter=section.adapter;
switch (sectionId) {
case SECTION_ROUTES:
    MultipleListAdapter multipleListAdapter=(MultipleListAdapter)adapter;
  int adapterId=multipleListAdapter.getAdapterId(innerPosition);
switch (adapterId) {
case ADAPTER_EARLIER:
  mGetEarlierRoutesTask=new GetEarlierRoutesTask();
mGetEarlierRoutesTask.execute(mJourneyQuery);
break;
case ADAPTER_LATER:
mGetLaterRoutesTask=new GetLaterRoutesTask();
mGetLaterRoutesTask.execute(mJourneyQuery);
break;
case ADAPTER_ROUTES:
Trip2 trip=(Trip2)mSectionedAdapter.getItem(position);
findRouteDetails(trip);
break;
}
break;
case SECTION_CHANGE_TIME:
Intent i=new Intent(this,ChangeRouteTimeActivity.class);
i.putExtra(EXTRA_JOURNEY_QUERY,mJourneyQuery);
startActivityForResult(i,REQUEST_CODE_CHANGE_TIME);
break;
}
}
 

Example 18

From project TransportsRennes, under directory /TransportsCommun/src/fr/ybo/transportscommun/activity/bus/.

Source file: AbstractDetailTrajet.java

  21 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(getLayout());
  setupActionBar();
  recuperationDonneesIntent();
  gestionViewsTitle();
  construireListe();
  ListView lv=getListView();
  lv.setFastScrollEnabled(true);
  lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    public void onItemClick(    AdapterView<?> adapterView,    View view,    int position,    long id){
      Adapter arretAdapter=adapterView.getAdapter();
      Cursor cursor=(Cursor)arretAdapter.getItem(position);
      Intent intent=new Intent(AbstractDetailTrajet.this,getDetailArretClass());
      intent.putExtra("idArret",cursor.getString(cursor.getColumnIndex("_id")));
      intent.putExtra("nomArret",cursor.getString(cursor.getColumnIndex("nom")));
      intent.putExtra("direction",direction.direction);
      intent.putExtra("macroDirection",trajet.macroDirection);
      intent.putExtra("ligne",ligne);
      startActivity(intent);
    }
  }
);
  lv.setTextFilterEnabled(true);
}
 

Example 19

From project android-bankdroid, under directory /src/com/liato/bankdroid/.

Source file: TransactionsActivity.java

  19 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  try {
    setContentView(R.layout.transactions_htc);
  }
 catch (  InflateException e) {
    setContentView(R.layout.transactions);
  }
  Bundle extras=getIntent().getExtras();
  Bank bank=BankFactory.bankFromDb(extras.getLong("bank"),this,false);
  Account account=BankFactory.accountFromDb(this,extras.getLong("bank") + "_" + extras.getString("account"),true);
  TextView viewBankName=(TextView)findViewById(R.id.txtListitemAccountsGroupAccountname);
  TextView viewAccountName=(TextView)findViewById(R.id.txtListitemAccountsGroupBankname);
  TextView viewAccountBalance=(TextView)findViewById(R.id.txtListitemAccountsGroupTotal);
  ImageView icon=(ImageView)findViewById(R.id.imgListitemAccountsGroup);
  viewBankName.setText(bank.getDisplayName());
  viewAccountName.setText(account.getName());
  viewAccountBalance.setText(Helpers.formatBalance(account.getBalance(),account.getCurrency()));
  icon.setImageResource(bank.getImageResource());
  ArrayList<Transaction> transactions=account.getTransactions();
  if (transactions.size() > 0) {
    findViewById(R.id.txtTranDesc).setVisibility(View.GONE);
    TransactionsAdapter adapter=new TransactionsAdapter(transactions);
    try {
      Class<?> c=Class.forName("com.htc.widget.HtcListView");
      Object viewTransactionsList=c.cast(findViewById(R.id.lstTransactionsList));
      Method method=c.getDeclaredMethod("setAdapter",Adapter.class);
      method.invoke(viewTransactionsList,adapter);
    }
 catch (    Exception e) {
      ListView viewTransactionsList=(ListView)findViewById(R.id.lstTransactionsList);
      viewTransactionsList.setAdapter(adapter);
    }
  }
}
 

Example 20

From project android-viewflow, under directory /viewflow/src/org/taptwo/android/widget/.

Source file: ViewFlow.java

  19 
vote

public void setAdapter(Adapter adapter,int initialPosition){
  if (mAdapter != null) {
    mAdapter.unregisterDataSetObserver(mDataSetObserver);
  }
  mAdapter=adapter;
  if (mAdapter != null) {
    mDataSetObserver=new AdapterDataSetObserver();
    mAdapter.registerDataSetObserver(mDataSetObserver);
  }
  if (mAdapter == null || mAdapter.getCount() == 0)   return;
  setSelection(initialPosition);
}
 

Example 21

From project iPhoroidUI, under directory /src/org/klab/iphoroid/widget/flowview/.

Source file: FlowView.java

  19 
vote

@Override public void setAdapter(Adapter adapter){
  if (mAdapter != null) {
    mAdapter.unregisterDataSetObserver(mDataSetObserver);
  }
  mAdapter=adapter;
  if (mAdapter != null) {
    mDataSetObserver=new AdapterDataSetObserver();
    mAdapter.registerDataSetObserver(mDataSetObserver);
  }
  if (mAdapter.getCount() == 0)   return;
  for (int i=0; i < Math.min(mAdapter.getCount(),mSideBuffer + 1); i++) {
    mLoadedViews.addLast(makeAndAddView(i,true,null));
  }
  mCurrentAdapterIndex=0;
  mCurrentBufferIndex=0;
  requestLayout();
  setVisibleView(mCurrentBufferIndex,false);
  if (mViewSwitchListener != null) {
    mViewSwitchListener.onSwitched(mLoadedViews.get(0),0);
  }
}
 

Example 22

From project liquidroid, under directory /src/liqui/droid/util/.

Source file: IndexScroller.java

  19 
vote

public void setAdapter(Adapter adapter){
  if (adapter instanceof SectionIndexer) {
    mIndexer=(SectionIndexer)adapter;
    mSections=(String[])mIndexer.getSections();
  }
}
 

Example 23

From project mWater-Android-App, under directory /android/src/co/mwater/clientapp/ui/.

Source file: SourceListActivity.java

  19 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.source_list);
  actionBar=getSupportActionBar();
  adapter=new SimpleCursorAdapter(this,R.layout.source_row,null,new String[]{"code","name","desc"},new int[]{R.id.code,R.id.name,R.id.desc},Adapter.NO_SELECTION);
  ListView listView=(ListView)findViewById(R.id.list);
  listView.setAdapter(adapter);
  listView.setOnItemClickListener(new OnItemClickListener(){
    public void onItemClick(    AdapterView<?> a,    View v,    int position,    long id){
      SourceListActivity.this.onItemClick(id);
    }
  }
);
  Intent intent=getIntent();
  if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
    String query=intent.getStringExtra(SearchManager.QUERY);
    this.query=query;
  }
  LocationManager locationManager=(LocationManager)getSystemService(LOCATION_SERVICE);
  locationFinder=new LocationFinder(locationManager);
  if (locationFinder.getLastLocation() != null)   getSupportLoaderManager().initLoader(LOADER_ID,null,this);
 else {
    progressDialog=ProgressDialog.show(this,"Sources","Waiting for location...");
  }
}
 

Example 24

From project platform_packages_apps_browser, under directory /src/com/android/browser/view/.

Source file: BasePieView.java

  19 
vote

public void setAdapter(Adapter adapter){
  mAdapter=adapter;
  if (adapter == null) {
    if (mAdapter != null) {
      mAdapter.unregisterDataSetObserver(mObserver);
    }
    mViews=null;
    mCurrent=-1;
  }
 else {
    mObserver=new DataSetObserver(){
      @Override public void onChanged(){
        buildViews();
      }
      @Override public void onInvalidated(){
        mViews.clear();
      }
    }
;
    mAdapter.registerDataSetObserver(mObserver);
    setCurrent(0);
  }
}
 

Example 25

From project SchoolPlanner4Untis, under directory /src/edu/htl3r/schoolplanner/gui/.

Source file: SelectScreen.java

  19 
vote

private int getPositionForItem(Adapter adapter,String item){
  for (int i=0; i < adapter.getCount(); i++) {
    if (adapter.getItem(i).equals(item)) {
      return i;
    }
  }
  return -1;
}
 

Example 26

From project TiVo-Commander, under directory /src/com/arantius/tivocommander/.

Source file: LinearListView.java

  19 
vote

public void setAdapter(Adapter adapter){
  if (this.adapter != null)   this.adapter.unregisterDataSetObserver(observer);
  this.adapter=adapter;
  adapter.registerDataSetObserver(observer);
  observer.onChanged();
}
 

Example 27

From project ToolkitForAndroid, under directory /src/main/java/com/apkits/android/widget/.

Source file: GalleryFlipper.java

  19 
vote

/** 
 * ??????????
 * @param adapter
 */
public void setAdapter(Adapter adapter){
  mAdapter=adapter;
  mAdapter.registerDataSetObserver(new FlipperObserver());
  mCurrentPosition=0;
  mCurrentViewNumber=0;
  mViewCaches[0].recycleView(mCurrentPosition);
  mViewCaches[1].recycleView(getNextPosition(mCurrentPosition));
  mViewCaches[2].recycleView(getPrevPosition(mCurrentPosition));
  mViewCaches[0].setOffset(0,0,mCurrentViewNumber);
  mViewCaches[1].setOffset(0,0,mCurrentViewNumber);
  mViewCaches[2].setOffset(0,0,mCurrentViewNumber);
}