Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add spinner to subtitle - as in the Play Music app for Android?

Play Music screenshot

Please refer to the attached image.

setListNavigationCallbacks(mSpinnerAdapter, mNavigationCallback) adds a spinner pivoted under "My Library", and I cannot add a sub-list under it. I am unable to find a method which adds a spinner for "ALL MUSIC", not messing up with the main title of the action bar.

Any help is appreciated !

like image 456
dev Avatar asked Sep 26 '13 05:09

dev


1 Answers

It appears like a customised ArrayAdapter You need to implement getDropDownView and return the view that you would like to see.

Feel free to modify the code. This is just a proof of concept. In your activity:

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    getActionBar().setTitle("");

    getActionBar().setListNavigationCallbacks(new MySpinnerAdapter(this, R.layout.customspinneritem, items), new OnNavigationListener() {

        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {

            return false;
        }
    });

MySpinnerAdapter:

 public class MySpinnerAdapter extends ArrayAdapter<String>{

// CUSTOM SPINNER ADAPTER
private Context mContext;
public MySpinnerAdapter(Context context, int textViewResourceId,
        String[] objects) {
    super(context, textViewResourceId, objects);

    mContext = context;
    // TODO Auto-generated constructor stub
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    return getCustomView(position, convertView, parent);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    return getCustomView(position, convertView, parent);
}

public View getCustomView(int position, View convertView,ViewGroup parent) {
// TODO Auto-generated method stub
// return super.getView(position, convertView, parent);


LayoutInflater inflater =  
    ( LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.customspinneritem, null);
holder = new ViewHolder();
holder.txt01 = (TextView) convertView.findViewById(R.id.TextView01);
holder.txt02 = (TextView) convertView.findViewById(R.id.TextView02);

convertView.setTag(holder);

} else {

holder = (ViewHolder) convertView.getTag();
}

holder.txt01.setText("My Library");
holder.txt02.setText("ALL MUSIC");

return convertView;
}

class ViewHolder {
    TextView txt01;
    TextView txt02;
}



} // end custom adapter

enter image description here

like image 146
prijupaul Avatar answered Sep 21 '22 17:09

prijupaul