2013-02-07 16 views

回答

0

爲什麼你想要它與微調不同?您可以設置微調器在選擇項目時開始活動。

playlistsSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> arg0, View arg1, 
       int pos, long arg3) { 
      Intent intent = new Intent(this, yourOtherActivity.class); 
      intent.putExtra("extra-pos", pos); 

      //or, if you want different activites then: 
      Intent newActivity; 
      switch (pos) { 
      case 0: 
       newActivity = new Intent(this, activityB.class); 
       break; 
      case 1: 
       newActivity = new Intent(this, activityC.class); 
       break; 
      default: 
       //do nothing 
       break; 
      } 
      if (newActivity != null) { 
       startActivity(newActivity); 
      } 
     } 

您還可以根據自己的喜好自定義微調器的外觀。

0

我會在此發佈基礎知識,但您可以在我們的github回購(https://github.com/todoroo/astrid)中找到更多詳細信息。基本的想法是按照hanry的建議擴展GreenDroid的QuickActionWidget。子類看起來類似:

public class MenuPopover extends QuickActionWidget { 

protected DisplayMetrics metrics; 
protected LinearLayout content; 

public MenuPopover(Context context) { 
    super(context); 
    setContentView(R.layout.my_layout); 

    content = (LinearLayout) getContentView().findViewById(R.id.content); 
    metrics = context.getResources().getDisplayMetrics(); 

    setFocusable(true); 
    setTouchable(true); 
} 

@Override 
protected void populateQuickActions(List<QuickAction> quickActions) { 
    // Do nothing 
} 

@Override 
protected void onMeasureAndLayout(Rect anchorRect, View contentView) { 
    contentView.setLayoutParams(new  FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,  ViewGroup.LayoutParams.WRAP_CONTENT)); 
    contentView.measure(MeasureSpec.makeMeasureSpec(getScreenWidth(),  MeasureSpec.EXACTLY), 
      ViewGroup.LayoutParams.WRAP_CONTENT); 

    int rootHeight = contentView.getMeasuredHeight(); 

    int offsetY = getArrowOffsetY(); 
    int dyTop = anchorRect.top; 
    int dyBottom = getScreenHeight() - anchorRect.bottom; 

    boolean onTop = (dyTop > dyBottom); 
    int popupY = (onTop) ? anchorRect.top - rootHeight + offsetY : anchorRect.bottom - offsetY; 

    setWidgetSpecs(popupY, onTop); 
} 
} 

佈局文件my_layout.xml很簡單:

<LinearLayout 
      android:id="@+id/content" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/gdi_arrow_up" 
      android:orientation="vertical"/> 

    <ImageView 
     android:id="@+id/gdi_arrow_up" 
     android:layout_width="27dip" 
     android:layout_height="27dip" 
     android:layout_marginLeft="-10dip" 
     android:scaleType="fitCenter" 
     android:layout_marginBottom="-8dip" 
     android:src="?attr/asListArrowUp" /> 

    <ImageView 
     android:id="@+id/gdi_arrow_down" 
     android:layout_width="27dip" 
     android:layout_height="27dip" 
     android:scaleType="fitCenter" 
     android:layout_marginBottom="-8dip" 
     android:layout_below="@android:id/list"/> 

    </RelativeLayout> 

然後,你可以添加一個簡單的helper方法的酥料餅類添加到popover的主體視圖(即行,與可選監聽器):

在實踐中,我們附上了一些附加信息,監聽器等,這些看法 -

創建彈出的一個實例後,可以通過調用

menuPopover.show(anchorView); 

這是一個很簡單的版本顯示它讓他們實際上點擊時做事情。如果你願意,你可以在https://github.com/todoroo/astrid查看完整的代碼 - 類是com.todoroo.astrid.ui.MainMenuPopover。

+0

嗨,你能告訴我們如何添加項目到列表中,我有點困惑。謝謝 – Naruto

相關問題