1

I've few weeks of experience with android and I'd like to create and fill programmatically an AutoCompleteTextView but I can't because the Activity stops. This is the code I wrote:

    public class ItemEditor extends LinearLayout {
  String[]  itemList = { "one", "two", "three" };

  public ItemEditor(Context context) {
    super(context);
    this.makeEditor(context);
  }

  void makeEditor(Context context) {
    AutoCompleteTextView item = new AutoCompleteTextView(context);
    item.setId(View.generateViewId());

    ArrayAdapter<String> itemArrayAdapter = new ArrayAdapter<String>(context,
        item.getId(), itemList);

    item.setAdapter(itemArrayAdapter);

    this.addView(item);
  }
}

and I use it as follows:

public class ItemEditorActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.activity_message_set_editor);
    this.setContentView(new MessageSetEditor(this));
  }
...
}

As soon as I try to show ItemEditorActivity, it stops. Any help would be appreciated. Regards

dommac
  • 11
  • 1

1 Answers1

0

I solved the problem by myself: in the array adapter declaration I used the id of the autocomplete widget instead of android.R.layout.select_dialog_item.

dommac
  • 11
  • 1