2017-12-28 27 views
0

私はcom.beardedhen.androidbootstrap.BootstrapDropDownで働いていると私はドロップダウンAndroidのブートストラップウィジェット

dropdownresource.xml

`<resources> 
    <string name="app_name">GTFirstPage</string> 
    <string name="navigation_drawer_open">Open navigation drawer</string> 
    <string name="navigation_drawer_close">Close navigation drawer</string> 
    <string name="action_settings">Settings</string> 
    <array name="bootstrap_dropdown_example_data"> 
    <item>Family Trip</item> 
    <item>Camping</item> 
    <item>Business Trip</item> 
    <item>{dropdown_separator}</item> 
    <item>Custom Trip</item> 
    </array> 
</resources>` 

プランから選択した項目の値を取得する方法を理解していません.xmlの

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.hp.gtfirstpage.plantrip"> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <AutoCompleteTextView 
     android:id="@+id/autotv1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left|center_horizontal|top" 
     android:layout_marginTop="25dp" 
     android:background="#f3f3f3" 
     android:hint="Where do you want to go?" 
     android:textSize="30sp"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="107dp" 
     android:orientation="horizontal" 

     android:weightSum="1"> 
     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="176dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="25dp" 
      android:text="Destination" 
      android:textSize="30sp" /> 

     <TextView 
      android:id="@+id/tv" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="25dp" 
      android:background="#f3f3f3" 
      android:ems="10" 
      android:textSize="20sp" 
      android:text="" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="107dp" 
     android:orientation="horizontal"> 
     <TextView 
      android:id="@+id/textView11" 
      android:layout_width="176dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:layout_weight="0.00" 
      android:text="Category" 
      android:textSize="30sp"/> 

     <com.beardedhen.androidbootstrap.BootstrapDropDown 

      android:id="@+id/spinner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      app:bootstrapBrand="regular" 
      app:bootstrapExpandDirection="down" 
      app:bootstrapSize="md" 
      app:bootstrapText="Select Category" 
      app:dropdownResource="@array/bootstrap_dropdown_example_data" 
      app:roundedCorners="true" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="107dp" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/textView13" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:text="Date" 
      android:textSize="30sp" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="85dp" 

      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/tv4" 
       android:layout_width="165dp" 
       android:layout_height="wrap_content" 
       android:ems="10" 
       android:textSize="20sp" 
       android:background="#f3f3f3" 
       android:inputType="date" /> 

      <TextView 
       android:id="@+id/textView14" 
       android:layout_width="45dp" 
       android:layout_height="wrap_content" 
       android:text="to" 
       android:textSize="30sp" /> 

      <TextView 
       android:id="@+id/tv5" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:ems="10" 
       android:textSize="20sp" 
       android:background="#f3f3f3" 
       android:inputType="date" /> 

     </LinearLayout> 

    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="107dp" 
     android:orientation="horizontal" 
     android:layout_marginTop="20dp"> 

     <Button 
      android:id="@+id/bt1" 
      android:layout_width="150dp" 
      android:layout_height="50dp" 
      android:layout_weight="1" 
      android:text="BACK" /> 

     <Button 
      android:id="@+id/bt2" 
      android:layout_width="150dp" 
      android:layout_height="50dp" 
      android:layout_weight="1" 
      android:text="DONE" /> 

    </LinearLayout> 

    </LinearLayout> 

    </FrameLayout> 

plantrip.java

package com.example.hp.gtfirstpage; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentTransaction; 
import android.widget.TextView; 
import android.widget.Toast; 
import com.beardedhen.androidbootstrap.BootstrapDropDown; 

public class plantrip extends Fragment implements 
    AdapterView.OnItemSelectedListener, DatePickerDialog.OnDateSetListener 
{  
    BootstrapDropDown spin; 
    String city,category,dest; 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) 
    { 
     View root=null; 
     root= inflater.inflate(R.layout.fragment_plantrip, container, false); 

     spin = (BootstrapDropDown) root.findViewById(R.id.spinner); 

     spin.setOnDropDownItemClickListener(new 
     BootstrapDropDown.OnDropDownItemClickListener() { 
     @Override 
     public void onItemClick(ViewGroup parent, View v, int id) { 
     // category=spin.getResources().getResourceName(spin.getId()); 
     } 
     }); 

    return root; 
    } 
} 

私はアンドロイドに新しいですので間違いがあれば正しく説明してください。 ドロップダウンリストからアイテムを取得する方法を教えてください。 ありがとうございました!

+0

Tyこの文字列text = spin.getSelectedItem()。toString(); – mehul

答えて

0

BootstrapDropDownには、getDropdownData()というメソッドがあります。 このメソッドは、BootstapDropDownの項目を含むString []配列を返します。配列のインデックスとしてint idを使用します。私はあなたがつかむことができると信じて

ます。public void onItemClick(のViewGroupの親、ビューV、int型のID){...}

: 'int型のidは' メソッドのパラメータとしてあなたに渡されます選択した項目をコードに追加してください:

String [] dropDownItems = spin.getDropdownData(); 文字列アイテム= dropDownItems [id];

spin.setOnDropDownItemClickListener(new 
    BootstrapDropDown.OnDropDownItemClickListener() { 
    @Override 
    public void onItemClick(ViewGroup parent, View v, int id) { 
    // category=spin.getResources().getResourceName(spin.getId()); 
      String[] dropDownItems = spin.getDropdownData(); 
      String item = dropDownItems[id]; 
    } 
    }); 

//は、私は、これは助けを願って間違い

//を修正するために編集のカップルを作りましたよ!

関連する問題