下拉列表應該有一個固定的預定義名稱,不像微調。 當點擊它的元素時,它們應該傳遞一個Intent以進行相應的活動。 希望有一個好的代碼。 謝謝。我們如何在android中創建一個自定義的下拉列表,與spinner不同?請幫我編碼
0
A
回答
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。
相關問題
- 1. 我們如何檢索Netsuite中的自定義列表的值(下拉列表)
- 2. cancan我們如何在ROR中創建角色下拉列表
- 3. 如何在自定義值的Excel中創建下拉列表
- 4. 自定義HTML幫助下拉列表
- 5. 如何創建下拉列表的默認自定義值
- 6. 如何在android中創建自定義下拉菜單
- 7. 如何在asp.net MVC中創建我的自定義幫助器?
- 8. WordPress的:在wp_get_archives下拉列表中創建自定義值
- 9. 如何創建一個下拉列表?
- 10. 如何創建一個下拉列表?
- 11. 如何在android中創建我們自己的自定義視圖
- 12. 請幫我如何自定義gridview
- 13. Android的下拉列表創建無Spinner組件
- 14. Android - 如何創建一個自定義(不同)的微調框
- 15. 如何動態填寫我的自定義下拉列表?
- 16. 在asp.net/c中創建自定義下拉列表#
- 17. 在angularjs中創建自定義下拉列表
- 18. 我們如何在phpfox中創建自定義頁面?
- 19. 我們如何在UIActivityViewController中創建自定義相冊ios
- 20. 我們如何指定一個自定義的lambda序列glmnet
- 21. 我需要爲同一行中的相同列創建依賴下拉列表
- 22. 如何在json請求中在android中創建和自定義列表頁面
- 23. 幫我創建我的數據庫中所有Jefes的下拉列表!
- 24. 我們如何填寫一個下拉列表以jqgrid級聯
- 25. 我們如何在實體框架中創建一個具有自定義列名作爲主鍵的表
- 26. 如何創建這個自定義的edittext?請幫助
- 27. 如何自定義Combobox下拉列表?
- 28. 如何在Android中創建我的自定義類?
- 29. 我們可以加入我們在sql中創建的同一個表嗎?
- 30. 請幫我創建一個SQL查詢
嗨,你能告訴我們如何添加項目到列表中,我有點困惑。謝謝 – Naruto