Android Attaching Multiple Adapters to One Adapter

android attaching multiple adapters to one adapter

Added this line:

setListAdapter(_sla);

below the line:

_sla.addSection("Results", _resultsAdapter);

Android setting more than one adapter to one listview

Try merging the 2 adapters into a single adapter like this :

android attaching multiple adapters to one adapter

Or, you could merge the two ArrayLists into one and then set the Adapter. Effectively that is what you are doing.

Or you could set the pcAPI into the adapter first, then add artistAPI to pcAPI and then set the new adapter again. and call adapter.notifyDataSetChanged().

why can't you simply do this?

pcAPI = (ArrayList<ListAPI>) parsepcAPI(pcTemp);
artistAPI = (ArrayList<ListAPI>) parseArtistAPI(artistTemp);

ArrayList<ListAPI> mergedList = new ArrayList<ListAPI>();
mergedList.addAll(pcAPI);
mergedList.add(artistAPI);

Song_APIAdapter adapter = new Song_APIAdapter(getApplicationContext(), mergedAPI);
lvAPI.setAdapter(adapter);

Setting more than one adapter for a single list view

Maybe you can try attaching multiple adapters to a single adapter like here

android attaching multiple adapters to one adapter

Or maybe this
http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/

if I understand what you need it for correctly

Pls update why you want it for so we have a better understanding

Multiple Adapters for a Card Listview

You can create a custom Adapter like this:

class ExampleAdapter extends BaseAdapter{

List<String> mTitles;
List<String> mContents;

@Override
public int getCount() {
return mTitles.size();
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View v;

//inflate view if needed
...

TextView tv_title;
TextView tv_content;

String title = mTitles.get(position);
String content = mContents.get(position);

tv_title.setText(title);
tv_content.setText(content);

return v;
}

}

Now past 2 list of String to this Adapter and call setAdapter of ListView.

Using multiple RecyclerView with one Adapter class

You can pass a tag in the constructor and get that tag back via a click listener to identify the click as

private final MarketsItemsClickListener mItemsClickListener;
private final MarketLongClickListener mLongClickListener;
private final MarketClickListener mClickListener;
private final String mTag;

public MarketAdapter(Context context, MarketsItemsClickListener itemsClickListener, MarketClickListener clickListener, MarketLongClickListener longClickListener, String tag){
mTag = tag
mContext = context;
mItemsClickListener = itemsClickListener;
mLongClickListener = longClickListener;
mClickListener = clickListener;
}

Modify the listener as

public interface MarketClickListener{
void onClick(int position, String tag);
}

and the listener code in activity as

@Override
public void onClick(int position, String tag) {
switch(tag){
case "adapter1":
break;
case "adapter2":
break;
case "adapter3":
break;
}
}

and create adapter object as

 MarketAdapter adapter = new MarketAdapter("adapter1"....); 
MarketAdapter adapter1 = new MarketAdapter("adapter2"....);
MarketAdapter adapter2 = new MarketAdapter("adapter3"....);

and use

mClickListener.onClick(position, mTag);

Note: You can use enums as well

Is it possible to set two adapters for single spinner in Android?

Not directly, but you can take a look to commonsguy's MergeAdapter, an Adapter implementation that accept multiple adapters and merges them into one single Adapter that you can pass to your spinner, if that's what you are looking for...



Related Topics



Leave a reply



Submit