Gmail的Andr​​oid应用程序一样而ActionView /微调(NAVIGATION_MODE_LIST) [英] Gmail Android App like ActionView/Spinner (NAVIGATION_MODE_LIST)

查看:81
本文介绍了Gmail的Andr​​oid应用程序一样而ActionView /微调(NAVIGATION_MODE_LIST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现NAVIGATION_MODE_LIST Gmail等Android应用程序。 我的主要问题是隐藏微调列表中的当前选择的项目。 因此,例如在此处显示如果您选择发送,然后它只会有在图示的其他元素微调。

I am trying to achieve NAVIGATION_MODE_LIST like gmail Android Application. My main issue is to hide the currently selected item from spinner list. so for example as shown here in if you select Sent then it will only have other elements shown in the spinner.

我的理解说,这是一个自定义而ActionView,而不是使用NAVIGATION_MODE_LIST定制的适配器。

My Understanding says that it is a custom ActionView rather than using NAVIGATION_MODE_LIST with custom adapter.

推荐答案

如果有人正在寻找解决这一问题,在这里它是,

If someone else is looking for the solution to this problem here it is,

下面是被写入了<一的帮助下样品code href="http://stackoverflow.com/questions/11410028/android-custom-adapter-with-custom-spinner-drop-down-xml-layout-giving-error">link

使用下面的code创建您的适配器,并加入到动作条列表导航

use following code to create your adapter and join it to ActionBar List Navigation

ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    itemArr = getResources().getStringArray(R.array.array_spinner_items);
    items = toArrayList(itemArr, null);

    navigationAdapter = new CustomAdapter(this, R.layout.navigation_item_layout, items);
    actionBar.setListNavigationCallbacks(navigationAdapter, this);
    actionBar.setDisplayShowTitleEnabled(false);

延长 BaseAdapter ArrayAdapter 实施SpinnerAdapter

在您的适配器覆盖getDropdownView负责单个项目视图下拉列表 并重写getView负责出现在动作条的看法

In your adapter override getDropdownView which is responsible for individual item view in dropdown and override getView which is responsible for the view appearing in the ActionBar

`公共类CustomAdapter扩展ArrayAdapter实现SpinnerAdapter {

`public class CustomAdapter extends ArrayAdapter implements SpinnerAdapter {

    Context context;
    int textViewResourceId;
    ArrayList<String> arrayList;

    public CustomAdapter(Context context, int textViewResourceId,  ArrayList<String> arrayList) {
        super(context, textViewResourceId, arrayList);

        this.context = context;
        this.textViewResourceId = textViewResourceId;
        this.arrayList = arrayList;

    }

    @Override
     public View getDropDownView(int position, View convertView, ViewGroup parent){
       if (convertView == null)
       {
         LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         //convertView = vi.inflate(android.R.layout.simple_spinner_dropdown_item, null);
         convertView = vi.inflate(R.layout.navigation_item_layout, null);
       }

       TextView textView = (TextView) convertView.findViewById(R.id.navigation_item);
       textView.setText(arrayList.get(position).toString());//after changing from ArrayList<String> to ArrayList<Object>

       if (position  == curitem) { 
          textView.setHeight(0);
      }
      else{
        textView.setHeight(60);
      }

       return convertView;
     }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null) {
            convertView = getLayoutInflater().inflate(R.layout.navigation_item_layout, null);
        }
        TextView textview = (TextView) convertView.findViewById(R.id.navigation_item);
        textview.setText(itemArr[position].toUpperCase());
        textview.setTextColor(Color.RED);
        return convertView;
    }

}`

下面是微调项navigation_tem_layout.xml

Here is the layout file for spinner item navigation_tem_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/navigation_item" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:padding="10dp" />

这篇关于Gmail的Andr​​oid应用程序一样而ActionView /微调(NAVIGATION_MODE_LIST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆