2014-07-14 39 views
0

所以我有一個應用程序3片段。其中一個片段涉及到添加字符到列表視圖,然後給他們武器和能力。武器和能力通過點擊添加按鈕時出現的自定義對話框給予角色。 該對話框包含一個帶有預定字符名稱列表的微調控件,然後包含3個需要用戶輸入字符應具有的能力數量的編輯文本。微調不顯示的內容

我的問題是,此對話框中的微調不顯示其內容。 每當我點擊對話框我得到這個:

W/InputEventReceiver:試圖完成一個輸入事件,但輸入事件接收器已被處置。

Rewards.java

public class Rewards extends Fragment { 

    private Button button; 
    Context mContext; 
    int lesserCount; 
    int greaterCount; 
    int exaltedCount; 
    Dialog addCharDialog; 
    Dialog lesserDialog; 
    Dialog greaterDialog; 
    Dialog exaltedDialog; 
    Spinner SpnLesser1; 
    Spinner SpnLesser2; 
    Spinner SpnLesser3; 
    Spinner SpnGreater1; 
    Spinner SpnGreater2; 
    Spinner SpnExalted; 
    Spinner SpnChar; 

    ArrayList<Character> chars = new ArrayList(); 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

     View rootView = inflater.inflate(R.layout.fragment_rewards, container, false); 
     View addCharDialogView = inflater.inflate(R.layout.character_add, container, false); 
     button = (Button) rootView.findViewById(R.id.btnadd); 

      mContext = getActivity(); 
     // custom dialogs 

     createAddDialog(addCharDialogView); 
     createLesserDialog(); 
     createGreaterDialog(); 
     createExaltedDialog(); 


     SpnLesser1 = (Spinner) rootView.findViewById(R.id.lesserspinner1); 
     SpnLesser2 = (Spinner) rootView.findViewById(R.id.lesserspinner2); 
     SpnLesser3 = (Spinner) rootView.findViewById(R.id.lesserspinner3); 
     SpnGreater1 = (Spinner) rootView.findViewById(R.id.greaterspinner1); 
     SpnGreater2 = (Spinner) rootView.findViewById(R.id.greaterspinner2); 
     SpnExalted = (Spinner) rootView.findViewById(R.id.exaltedspinner); 


     return rootView; 
    } 

public View createAddDialog(View addCharDialogView) { 

    LayoutInflater inflater = LayoutInflater.from(this.getActivity()); 


    addCharDialog = new Dialog(mContext); 
    addCharDialog.setContentView(R.layout.character_add); 
    addCharDialog.setTitle("Add a character"); 

    SpnChar = (Spinner) addCharDialogView.findViewById(R.id.dialog_spinner); 

    ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(getActivity().getBaseContext(),R.array.item_array, R.layout.spinner_layout); 
    //ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(addCharDialogView.getContext(),R.array.item_array, R.layout.spinner_layout); 
    dataAdapter.setDropDownViewResource 
      (android.R.layout.simple_spinner_dropdown_item); 

    SpnChar.setAdapter(dataAdapter); 


    //spinner is populated but it's not displaying and won't do anything when clicked on 

    SpnChar.setSelection(2); 

    String Text = SpnChar.getSelectedItem().toString(); 

    Log.d("2", Text); 


    Button dialogOkButton = (Button) addCharDialog.findViewById(R.id.dialogOK); 
    // if button is clicked, close the custom dialog 
    dialogOkButton.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      lesserCount = R.id.lessertext; 
      greaterCount = R.id.greatertext; 
      exaltedCount = R.id.exaltedtext; 

      Character c; 

      if (lesserCount > 0) { 
       lesserDialog.show(); 
      } 

      if (greaterCount > 0) { 
       greaterDialog.show(); 
      } 
      if (exaltedCount > 0) { 
       exaltedDialog.show(); 
      } 
     } 
    }); 

    Button dialogCancelButton = (Button) addCharDialog.findViewById(R.id.dialogCancel); 
    // if button is clicked, close the custom dialog 
    dialogCancelButton.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      addCharDialog.dismiss(); 
     } 
    }); 
    // add button listener 
    button.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 


      addCharDialog.show(); 
     } 
    }); 

return addCharDialogView; 
} 

    } 
} 

character_add.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<!--<TextView--> 
    <!--android:id="@+id/dialog_label"--> 
    <!--android:layout_height="wrap_content"--> 
    <!--android:layout_width="fill_parent"--> 
    <!--android:hint="Please select an option"--> 
    <!--/>--> 
<Spinner 
    android:id="@+id/dialog_spinner" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    /> 
<Button 
    android:id="@+id/dialogOK" 
    android:layout_width="120dp" 
    android:layout_height="wrap_content" 
    android:text="OK" 
    android:layout_marginTop="113dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentStart="true" /> 
<Button 
    android:id="@+id/dialogCancel" 
    android:layout_width="120dp" 
    android:layout_height="wrap_content" 
    android:text="Cancel" 
    android:layout_alignTop="@+id/dialogOK" 
    android:layout_toRightOf="@+id/dialogOK" /> 

<EditText 
    android:layout_width="60dp" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/lessertext" 
    android:layout_below="@+id/dialog_spinner" 
    android:layout_toRightOf="@+id/editText8" 
    android:text="0" /> 

<EditText 
    android:layout_width="60dp" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/greatertext" 
    android:layout_below="@+id/dialog_spinner" 
    android:layout_toRightOf="@+id/editText9" 
    android:text="0" /> 

<EditText 
    android:layout_width="60dp" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/exaltedtext" 
    android:layout_below="@+id/dialog_spinner" 
    android:layout_toRightOf="@+id/editText10" 
    android:text="0" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText8" 
    android:layout_below="@+id/dialog_spinner" 
    android:layout_alignParentStart="true" 
    android:text="L" /> 

<EditText 
    android:layout_width="50dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText9" 
    android:layout_below="@+id/dialog_spinner" 
    android:layout_toRightOf="@+id/lessertext" 
    android:text="G" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/editText10" 
    android:layout_below="@+id/dialog_spinner" 
    android:layout_toRightOf="@+id/greatertext" 
    android:text="E" /> 

+0

你嘗試添加一個onItemSelectedListener爲你的微調嗎? – Droidekas

+0

出於好奇,你創造了什麼樣的遊戲? – KingsInnerSoul

回答

0

如果我理解正確的,你想,可以在顯示輸入用戶鍵入一個微調?如果是這樣,你可以使用一個Arraylist並創建一個方法,在每次內容改變時會破壞你的微調並重新創建它。你可以如下設置:

ArrayList<String> thing = new ArrayList<String>(); 
ViewGroup layout = null; 
layout = (ViewGroup) spinner.getParent(); 

    public void addSpinner(ArrayList thing){ 

     layout.removeView(spinner); 
        layout.addView(spinnersy2); 

     spinner =(Spinner) findViewById(R.id.spinner1);  
     ArrayAdapter <String>adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, thing); 
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spinner.setAdapter(adapter); 
     spinner.setOnItemSelectedListener(this); 
    } 

創建第二種方法,將用戶輸入添加到數組中。