2014-09-29 65 views
0

請誰能告訴我如何與微調安卓:如何微調模樣的TextView和ONCLICK上微調打開對話框自定義列表視圖

這是我的第一個屏幕旋轉設計這個佈局

enter image description here

這是我的屏幕,打開對話框,custon ListView控件的onclick選擇城市微調的

enter image description here

和onselecting它在第一次屏幕顯示對話框項目是微調的功能..

任何人都可以建議我如何做到這一點?

在此先感謝..

+0

您是否嘗試將onClickListener設置爲文本視圖?在onClick()方法內部,您可以使用listview顯示您的自定義對話框。 – DrMartens 2014-09-29 12:32:44

+0

是的,但我的問題是,像我選擇國家時依賴,然後自動更改城市。所以我使用微調,因爲它的onItemSelected方法是有用的 – SAndroidD 2014-09-29 12:43:08

+0

因此,在微調適配器,你可以膨脹你的自定義用戶界面的微調。不要忘記正確覆蓋getDropDownView()和getView()方法 – DrMartens 2014-09-29 12:52:03

回答

0

您可以按照以下步驟操作。

1)有一個TextView而不是Spinner,RegisterOnclick Listener就可以了。 2)在onClick事件中,用列表視圖啓動一個對話框。 Tutorial

3)從列表視圖/對話框中選擇項目,再次在列表視圖中設置。

1

快速修復:

  • 創建一個自定義的相對佈局,並把一個微調到第一個屏幕上進行書寫浦那的地方。使紡紗器背景透明或與相關佈局顏色相同。

    機器人:從XML

  • 集紡紗模式dialogMode spinnerMode = 「對話框」

  • 設置新onClickListener你相對佈局和投入:

    mySpinner.performClick();

  • 最後,在您的微調器適配器中,像在第二個屏幕中一樣定義自定義微調器行佈局。

+0

感謝,但如何微調看起來像textview – SAndroidD 2014-09-29 13:02:00

+0

我不明白你說的意思是什麼時候你說「看起來像一個textview」,但如果你設置微調的背景透明,我認爲它會看起來像一個文本視圖。 – savepopulation 2014-09-29 13:20:35

+0

我的意思是微調視圖看起來像簡單的文本視圖,並點擊打開對話框列表。我設置了spinner的屬性spinnerMode =「dialog」,但是如何讓SpinnerView看起來像簡單的textview – SAndroidD 2014-09-30 05:26:46

0

用spinner_layout.xml中的文本視圖指定佈局。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

<TextView 
    android:id="@+id/id_of_your_textView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

</LinearLayout> 

在適配器類做:

//members 
    protected Context context; 
    protected LayoutInflater inflater; 
//constructor 
public CustomArrayAdapter(Context context) { 
     super(context, resource); 
     this.context = context; 
     inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 
//override method getView 
@Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
      View element = inflater.inflate(R.layout.spinner_layout, parent, false); 
      TextView textView = (TextView)element.findViewById(R.id.id_of_your_textView); 
      textView.setText("blah-blah"); 
      return element; 
     } 

它應該是足夠的。 如果您的微調項目應顯示覆雜的項目,請不要忘記覆蓋 getDropDownView(int position,View convertView,ViewGroup parent)方法。