2011-12-17 16 views
1

この1つは私に非常に困っています。私はそれがちょうど私が行方不明であることを確信していますが、私は何を見つけることができます...カスタムArrayAdapterは結果を表示しません

私は、プログラムを実行すると、ダイアログボックスを開き、私が初期化したAutoCompleteTextViewを表示します。私はそれに何かを入力しようとすると、何もドロップダウンや私は入力したテキスト以外の表示されます。私は同じメカニックで私のプログラムの別の部分で同様のシステムを作成したが、通常のArrayAdapterを使用し、インターフェイスは問題ではありません。

ここで私のカスタムArrayListを初期化します。私はそれをより簡単にするために文字列を使用しようとしてきました。

final Dialog weaponDialog = new Dialog(BattleScreen.this); 
     weaponDialog.setContentView(R.layout.weapon_selection_dialog); 
     weaponDialog.setTitle("Add a Weapon"); 
     weaponDialog.setCancelable(true); 

     String[] weaponStringArrayList = ConstantEquipmentHelper.getCondensedWeaponString(); 

     WeaponArrayAdapter weaponAdapter = new WeaponArrayAdapter(this, R.layout.weapon_list_item, weaponStringArrayList); 

     weaponDialogAcTextView = (AutoCompleteTextView) weaponDialog.findViewById(R.id.weaponSelectionAutoCompleteTxt); 
     weaponDialogAddButton = (Button) weaponDialog.findViewById(R.id.weaponSelectionAddButton); 
     weaponDialogWeaponInfo = (TextView) weaponDialog.findViewById(R.id.weaponSelectionInformationTxt); 
... 
... 
... 

は、ここに私の習慣ですArrayAdapterクラス

public class WeaponArrayAdapter extends ArrayAdapter<String> { 

    private Context context; 
    String[] objects; 

    public WeaponArrayAdapter(Context context, int textViewResourceId, String[] objects) { 
     super(context, textViewResourceId); 
     this.objects = objects; 
     this.context = context; 
    } 

    private class WeaponItemHolder { 
     TextView weaponName; 
     TextView weaponCat; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     //return super.getView(position, convertView, parent); 
     final WeaponItemHolder holder; 
     if (convertView == null) { 
      //Sets up a new holder to temporaraly hold the listeners that will be assigned to the binded variables 
      holder = new WeaponItemHolder(); 

      inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

      convertView = inflater.inflate(R.layout.weapon_list_item, null); 

      //Find the IDs! Find them!!!! 
      holder.weaponName = (TextView) convertView.findViewById(R.id.weaponListItemName); 
      holder.weaponCat = (TextView) convertView.findViewById(R.id.weaponListItemCategory); 

      //"Sets the tag associated with this view. A tag can be used 
      //to mark a view in its hierarchy and does not have to be unique within the hierarchy." 
      convertView.setTag(holder); 
     } else { 
      holder = (WeaponItemHolder) convertView.getTag(); 
     } 

     String spellName = objects[position]; 

     String[] weaponInfo = spellName.split("\\:"); 
     weaponInfo[1] = weaponInfo[1].trim(); 

     holder.weaponName.setText(weaponInfo[0]); 
     holder.weaponCat.setText(weaponInfo[1]); 

     return convertView; 
    } 

} 

追加情報:私はそれをデバッグしようとしていると、それはgetViewメソッドに達することはありません。これは何も表示しないので、もちろん意味があります。

おかげで、 -Andrew

編集:私は、上記の問題を実装する方法を見出した:

私はカスタムレイアウトでSimpleAdapterを使用。 しかし、今はアイテムを選択できません...クリックしようとするとonItemClickは呼び出されません。 SimpleAdapterの使用とおそらく関係していますか?

LINK:http://lemonbloggywog.wordpress.com/2011/02/15/customer-autocomplete-contacts-android/

ArrayList<Map<String, String>> weaponStringArrayList = ConstantEquipmentHelper.getCondensedWeaponString(); 


     //The adapter that recieves the layout type from android and the array creatd by the above function. 
     SimpleAdapter simpleAdapter = new SimpleAdapter(this, weaponStringArrayList, R.layout.weapon_list_item ,new String[] {"name", "category"}, new int[] { R.id.weaponListItemName, R.id.weaponListItemCategory}); 

     //Find the view blah blah blah... 
     weaponDialogAcTextView = (AutoCompleteTextView) weaponDialog.findViewById(R.id.weaponSelectionAutoCompleteTxt); 
     weaponDialogAddButton = (Button) weaponDialog.findViewById(R.id.weaponSelectionAddButton); 
     weaponDialogWeaponInfo = (TextView) weaponDialog.findViewById(R.id.weaponSelectionInformationTxt); 

     //Set that adapter! 
     weaponDialogAcTextView.setAdapter(simpleAdapter); 

答えて

0

あなたは同様にgetCount()を実装し、すなわちobjects.length、あなたのデータの数を設定する必要があります。

また、setAdapter()メソッドを使用して、アダプタをビューに設定する必要があります。

希望すると便利です。

+0

私はそれを加えましたが、それはまだ同じように動作しています。デバッグがgetCount()に到達しませんでした。 –

+0

更新された回答を確認してください。 –

+0

これで運がいい? –

関連する問題