2017-12-28 28 views
0

내가 com.beardedhen.androidbootstrap.BootstrapDropDown 함께 일하고 내가 드롭 다운안드로이드 부트 스트랩 위젯

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 this String text = spin.getSelectedItem(). toString(); – mehul

답변

0

BootstrapDropDown에는 getDropdownData()라는 메서드가 있습니다. 이 메서드는 BootstapDropDown의 항목이 포함 된 String [] 배열을 반환합니다. 배열의 인덱스로 int id를 사용하십시오. 난 당신이 잡아 수 있다고 생각

공공 무효 onItemClick (뷰 그룹 부모,보기 V, INT 아이디) {...}

: '내부 ID가'방법의 매개 변수로 당신에게 전달됩니다 선택한 항목을 코드에 다음 줄을 추가하여 선택하십시오.

String [] dropDownItems = spin.getDropdownData(); String item = 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]; 
    } 
    }); 

// 내가 희망이 도움이 // 실수를

를 해결하기 위해 편집의 몇했다!