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

后端 未结 3 1659
谎友^
谎友^ 2020-12-13 15:53

\"Play

Please refer to the attached image.

setListNavigationCallbacks(mSpinne

3条回答
  •  误落风尘
    2020-12-13 16:35

    Here is the solution. We need to create a different method for getView(...) and also need to keep track on the item selected from drop down. Once the item from navigation drawer is clicked call a new method (create new method in spinner adapter as update title) llike

    public void setHeaderTitle(String str) { titleTxt = str; }

    Different method called from get view

    @Override
         public View getView(int position, View convertView, ViewGroup parent) {
    
            return getBarView(position);
        }
    
    private View getBarView(int position) {
            if (displayHolder == null) {
                LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView1 = inflater.inflate(R.layout.actionbar_spinner_item, null);
                displayHolder = new ViewHolder();
            }
    
            displayHolder.txt01 = (TextView) convertView1.findViewById(R.id.actionBarTitle123);
            displayHolder.txt02 = (TextView) convertView1.findViewById(R.id.actionBarSubTitle123);
            displayHolder.txt01.setText(titleTxt);
            displayHolder.txt02.setText(items[curPos]);
    
            return convertView1;
        }
    

    And when drop down item is selected call below method

    public void setHeaderSubTitle(int pos) {
    
            // update display of sub title
            curPos = pos;
            getBarView(pos);
        }
    

    Let me know anything more is needed

提交回复
热议问题