【问题标题】:new expandable listview highly customizable新的可扩展列表视图高度可定制
【发布时间】:2011-11-14 18:48:58
【问题描述】:

我需要在图片中实现类似的东西: “TITLE”矩形列出了一个对象,当我单击其中一个对象时,会打开一个“子菜单”(其中有 ELEMENT #1、2 等)。该系统类似于可扩展的列表视图,但更可定制。

您建议如何实现这一点? 如何为子菜单的折叠制作动画?如果我将子菜单设置为“消失”,然后当 onClick 标题设置为可见性 = 可见时突然出现...我想要一些 Android 风格的动画。

你有什么建议?每次我需要实现类似的东西时,我都在考虑实现一个要实例化的对象。

【问题讨论】:

    标签: android listview object expandablelistview


    【解决方案1】:
                        CustomListViewDemo.java 
    
    public class CustomListViewDemo extends ListActivity {
      private EfficientAdapter adap;
    
      private static String[] data = new String[] { "0", "1", "2", "3", "4" };
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        adap = new EfficientAdapter(this);
        setListAdapter(adap);
      }
    
      @Override
      protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        Toast.makeText(this, "Click-" + String.valueOf(position), Toast.LENGTH_SHORT).show();
      }
    
      public static class EfficientAdapter extends BaseAdapter implements Filterable {
        private LayoutInflater mInflater;
        private Bitmap mIcon1;
        private Context context;
        int firstpos=0;
    
        public EfficientAdapter(Context context) {
          // Cache the LayoutInflate to avoid asking for a new one each time.
          mInflater = LayoutInflater.from(context);
          this.context = context;
        }
    
        public View getView(final int position, View convertView, ViewGroup parent) {
    
          ViewHolder holder;
    
          if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adaptor_content, null);
    
            holder = new ViewHolder();
            holder.sp = (Spinner) convertView.findViewById(R.id.spinner1);
    
            holder.ArrayAdapter_sp = new ArrayAdapter(parent.getContext(),android.R.layout.simple_spinner_item,data);
            holder.ArrayAdapter_sp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    
            holder.sp.setAdapter( holder.ArrayAdapter_sp);
            holder.sp.setOnItemSelectedListener(new OnItemSelectedListener()
            {
                private int pos = position;
                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int p, long arg3) 
                {
                    // TODO Auto-generated method stub
                     Toast.makeText(context, "select spinner " + String.valueOf(pos)+" with value ID "+p, Toast.LENGTH_SHORT).show();    
    
                }
    
                @Override
                public void onNothingSelected(AdapterView<?> arg0)
                {
                    // TODO Auto-generated method stub
    
                }
            });
    
    
    
    
            convertView.setTag(holder);
          } else {
    
            holder = (ViewHolder) convertView.getTag();
          }
    
    
          return convertView;
        }
    
        static class ViewHolder 
        {
    
            Spinner sp;
            ArrayAdapter ArrayAdapter_sp;
    
        }
    
        @Override
        public Filter getFilter() {
          // TODO Auto-generated method stub
          return null;
        }
    
        @Override
        public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
        }
    
        @Override
        public int getCount() {
          // TODO Auto-generated method stub
          return data.length;
        }
    
        @Override
        public Object getItem(int position) {
          // TODO Auto-generated method stub
          return data[position];
        }
    
      }
    
    }
    
    ----------------------------------------------------------------------------------
                            adaptor_content.xml
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/lineItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical" >
    
        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="314dp"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    
    
    --------------------------------------------------------------------------
                            main.xml
    
    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent" android:layout_width="fill_parent"
        >
    
        <ListView
            android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="60dip"
            android:layout_marginTop="10dip"
            android:cacheColorHint="#00000000"
            android:drawSelectorOnTop="false" />
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      相关资源
      最近更新 更多