コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) return;
    onInflate(savedInstanceState);
    if (isFinishing()) return;
    Collection<String> groups;
    Collection<String> selected;
    if (savedInstanceState != null) {
      groups = savedInstanceState.getStringArrayList(SAVED_GROUPS);
      selected = savedInstanceState.getStringArrayList(SAVED_SELECTED);
    } else {
      groups = getInitialGroups();
      selected = getInitialSelected();
    }

    listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setOnItemClickListener(this);
    arrayAdapter =
        new ArrayAdapter<>(
            this, android.R.layout.simple_list_item_multiple_choice, new ArrayList<String>());
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.add_item, listView, false);
    ((TextView) view.findViewById(android.R.id.message)).setText(R.string.group_add);
    listView.addFooterView(view, null, true);
    setListAdapter(arrayAdapter);
    setGroups(groups, selected);
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) return;

    actionWithItem = null;

    setContentView(R.layout.status_editor);

    Intent intent = getIntent();
    account = StatusEditor.getAccount(intent);
    if (account == null) setTitle(getString(R.string.status_editor));
    else
      setTitle(
          getString(
              R.string.status_editor_for, AccountManager.getInstance().getVerboseName(account)));

    ListView listView = getListView();
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View header = inflater.inflate(R.layout.status_editor_header, listView, false);
    listView.addHeaderView(header, null, false);
    listView.setOnItemClickListener(this);
    registerForContextMenu(listView);
    setListAdapter(new StatusEditorAdapter(this));

    statusTextView = (EditText) header.findViewById(R.id.status_text);
    statusModeView = (Spinner) header.findViewById(R.id.status_mode);
    statusModeView.setAdapter(new StatusModeAdapter(this));
    ((Button) findViewById(R.id.ok)).setOnClickListener(this);

    StatusMode statusMode;
    String statusText;
    if (savedInstanceState == null) {
      if (account == null) {
        statusMode = SettingsManager.statusMode();
        statusText = SettingsManager.statusText();
      } else {
        AccountItem accountItem = AccountManager.getInstance().getAccount(account);
        if (accountItem == null) {
          Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
          finish();
          return;
        }
        statusMode = accountItem.getFactualStatusMode();
        statusText = accountItem.getStatusText();
      }
    } else {
      statusMode = StatusMode.valueOf(savedInstanceState.getString(SAVED_MODE));
      statusText = savedInstanceState.getString(SAVED_TEXT);
    }
    showStatus(statusMode, statusText);
  }