2011-11-14 43 views
4

我需要認識到,類似的東西在圖片: enter image description here 「TITLE」矩形使得對象的列表,當我點擊這些對象之一是開設了「子菜單」(哪裏有元素#1,2等)。該系統類似於可擴展列表視圖,但更具可定製性。新的可擴展的ListView高度可定製的

你如何建議意識到這一點? 我怎樣才能做一個子菜單崩潰的動畫?如果我設置子菜單消失,然後當onClick標題我設置與可見性=可見突然出現...我想在Android風格動畫的東西。

你有什麼建議?每當我需要意識到這樣的事情時,我都在想要實現一個客觀的東西。

回答

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>