Search in sources :

Example 81 with ListView

use of android.widget.ListView in project Android-AccountChooser by frakbot.

the class ChooseAccountTypeActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "ChooseAccountTypeActivity.onCreate(savedInstanceState=" + savedInstanceState + ")");
    }
    // Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
    Set<String> setOfAllowableAccountTypes = null;
    String[] validAccountTypes = getIntent().getStringArrayExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
    if (validAccountTypes != null) {
        setOfAllowableAccountTypes = new HashSet<String>(validAccountTypes.length);
        for (String type : validAccountTypes) {
            setOfAllowableAccountTypes.add(type);
        }
    }
    // create a map of account authenticators
    buildTypeToAuthDescriptionMap();
    // Create a list of authenticators that are allowable. Filter out those that
    // don't match the allowable account types, if provided.
    mAuthenticatorInfosToDisplay = new ArrayList<AuthInfo>(mTypeToAuthenticatorInfo.size());
    for (Map.Entry<String, AuthInfo> entry : mTypeToAuthenticatorInfo.entrySet()) {
        final String type = entry.getKey();
        final AuthInfo info = entry.getValue();
        if (setOfAllowableAccountTypes != null && !setOfAllowableAccountTypes.contains(type)) {
            continue;
        }
        mAuthenticatorInfosToDisplay.add(info);
    }
    if (mAuthenticatorInfosToDisplay.isEmpty()) {
        Bundle bundle = new Bundle();
        bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "no allowable account types");
        setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
        finish();
        return;
    }
    if (mAuthenticatorInfosToDisplay.size() == 1) {
        setResultAndFinish(mAuthenticatorInfosToDisplay.get(0).desc.type);
        return;
    }
    setContentView(R.layout.choose_account_type);
    // Setup the list
    ListView list = (ListView) findViewById(android.R.id.list);
    // Use an existing ListAdapter that will map an array of strings to TextViews
    list.setAdapter(new AccountArrayAdapter(this, android.R.layout.simple_list_item_1, mAuthenticatorInfosToDisplay));
    list.setChoiceMode(ListView.CHOICE_MODE_NONE);
    list.setTextFilterEnabled(false);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            setResultAndFinish(mAuthenticatorInfosToDisplay.get(position).desc.type);
        }
    });
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) HashMap(java.util.HashMap) Map(java.util.Map)

Example 82 with ListView

use of android.widget.ListView in project Android-AccountChooser by frakbot.

the class ChooseTypeAndAccountActivity method populateUIAccountList.

/**
     * Populates the UI ListView with the given list of items and selects an item
     * based on {@code mSelectedItemIndex} member variable.
     */
private final void populateUIAccountList(String[] listItems) {
    ListView list = (ListView) findViewById(android.R.id.list);
    list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, listItems));
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setItemsCanFocus(false);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            mSelectedItemIndex = position;
            mOkButton.setEnabled(true);
        }
    });
    if (mSelectedItemIndex != SELECTED_ITEM_NONE) {
        list.setItemChecked(mSelectedItemIndex, true);
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "List item " + mSelectedItemIndex + " should be selected");
        }
    }
}
Also used : ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 83 with ListView

use of android.widget.ListView in project AndroidSDK-RecipeBook by gabu.

the class Recipe093 method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // 外部ストレージにある音楽データのUri
    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    // 取得するカラム(今回は無指定=すべて)
    String[] projection = null;
    // 検索条件
    String selection = null;
    // 検索条件の値
    String[] selectionArgs = null;
    // ソート条件
    String sortOrder = null;
    // 検索結果をCursorで取得しつつ、
    // カーソルの管理をアクティビティに任せる
    Cursor cursor = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
    for (String column : cursor.getColumnNames()) {
        Log.d(TAG, column);
    }
    // ListViewに表示するカラム名の配列
    String[] from = { // タイトル
    MediaStore.Audio.AudioColumns.TITLE, // アーティスト名
    MediaStore.Audio.AudioColumns.ARTIST, // 曲の長さ
    MediaStore.Audio.AudioColumns.DURATION };
    // fromに対応するビューのリソースID
    int[] to = { R.id.title, R.id.artist, R.id.duration };
    // SimpleCursorAdapterを生成
    SimpleCursorAdapter adapter;
    adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.row, cursor, from, to);
    // Viewにセットする値を加工するためViewBinderをセット
    adapter.setViewBinder(new AudioListViewBinder());
    // ListViewにAdapterをセット
    ListView listView = (ListView) findViewById(R.id.list_view);
    listView.setAdapter(adapter);
}
Also used : ListView(android.widget.ListView) SimpleCursorAdapter(android.widget.SimpleCursorAdapter) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 84 with ListView

use of android.widget.ListView in project KenBurnsView by flavioarfaria.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.main_options, android.R.layout.simple_list_item_1);
    final ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            onListItemClick(parent, view, position, id);
        }
    });
}
Also used : ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 85 with ListView

use of android.widget.ListView in project XobotOS by xamarin.

the class ListFragment method ensureList.

private void ensureList() {
    if (mList != null) {
        return;
    }
    View root = getView();
    if (root == null) {
        throw new IllegalStateException("Content view not yet created");
    }
    if (root instanceof ListView) {
        mList = (ListView) root;
    } else {
        mStandardEmptyView = (TextView) root.findViewById(com.android.internal.R.id.internalEmpty);
        if (mStandardEmptyView == null) {
            mEmptyView = root.findViewById(android.R.id.empty);
        } else {
            mStandardEmptyView.setVisibility(View.GONE);
        }
        mProgressContainer = root.findViewById(com.android.internal.R.id.progressContainer);
        mListContainer = root.findViewById(com.android.internal.R.id.listContainer);
        View rawListView = root.findViewById(android.R.id.list);
        if (!(rawListView instanceof ListView)) {
            throw new RuntimeException("Content has view with id attribute 'android.R.id.list' " + "that is not a ListView class");
        }
        mList = (ListView) rawListView;
        if (mList == null) {
            throw new RuntimeException("Your content must have a ListView whose id attribute is " + "'android.R.id.list'");
        }
        if (mEmptyView != null) {
            mList.setEmptyView(mEmptyView);
        } else if (mEmptyText != null) {
            mStandardEmptyView.setText(mEmptyText);
            mList.setEmptyView(mStandardEmptyView);
        }
    }
    mListShown = true;
    mList.setOnItemClickListener(mOnClickListener);
    if (mAdapter != null) {
        ListAdapter adapter = mAdapter;
        mAdapter = null;
        setListAdapter(adapter);
    } else {
        // have our data right away and start with the progress indicator.
        if (mProgressContainer != null) {
            setListShown(false, false);
        }
    }
    mHandler.post(mRequestFocus);
}
Also used : ListView(android.widget.ListView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListAdapter(android.widget.ListAdapter)

Aggregations

ListView (android.widget.ListView)1139 View (android.view.View)739 AdapterView (android.widget.AdapterView)444 TextView (android.widget.TextView)389 ImageView (android.widget.ImageView)167 Intent (android.content.Intent)148 AbsListView (android.widget.AbsListView)135 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)97 ArrayAdapter (android.widget.ArrayAdapter)97 ArrayList (java.util.ArrayList)81 ViewGroup (android.view.ViewGroup)75 ListAdapter (android.widget.ListAdapter)71 OnClickListener (android.view.View.OnClickListener)65 LayoutInflater (android.view.LayoutInflater)63 Bundle (android.os.Bundle)57 Button (android.widget.Button)55 LinearLayout (android.widget.LinearLayout)50 SuppressLint (android.annotation.SuppressLint)34 DialogInterface (android.content.DialogInterface)34 ScrollView (android.widget.ScrollView)31