Example usage for android.support.v4.widget SimpleCursorAdapter SimpleCursorAdapter

List of usage examples for android.support.v4.widget SimpleCursorAdapter SimpleCursorAdapter

Introduction

In this page you can find the example usage for android.support.v4.widget SimpleCursorAdapter SimpleCursorAdapter.

Prototype

@Deprecated
public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) 

Source Link

Document

Constructor the enables auto-requery.

Usage

From source file:com.narkii.security.info.BaseDataFragment.java

@SuppressWarnings("deprecation")
@Override/*from   w ww  .  j av a2 s .  c  o m*/
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
    initViews();
    initListener();
    areAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, null,
            new String[] { Area.COLUMN_NAME }, new int[] { android.R.id.text1 });
    areAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    areaSpinner.setAdapter(areAdapter);

    typeAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, null,
            new String[] { EnterpriseType.COLUMN_NAME }, new int[] { android.R.id.text1 });
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    typeSpinner.setAdapter(typeAdapter);

    getLoaderManager().initLoader(Constants.SPINNER_AREA_ID, null, this);
    getLoaderManager().restartLoader(Constants.SPINNER_ENTERPRISE_TYPE_ID, null, this);

    Log.d(TAG, "id:" + getArguments().getLong("enterpriseId", 0));
    enterpriseId = getArguments().getLong("enterpriseId", 0);
    if (enterpriseId == 0) {//

    } else {//
        Bundle bundle = new Bundle();
        bundle.putLong("id", enterpriseId);
        getLoaderManager().restartLoader(Constants.ENTERPRISE_INFO_ID, bundle, this);
        getLoaderManager().restartLoader(Constants.ENTERPRISE_PERSON_ID, bundle, this);
    }
}

From source file:info.guardianproject.otr.app.im.app.AddContactActivity.java

private void setupAccountSpinner() {
    final Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT;

    mCursorProviders = managedQuery(uri, PROVIDER_PROJECTION,
            Imps.Provider.CATEGORY + "=?" + " AND " + Imps.Provider.ACTIVE_ACCOUNT_USERNAME
                    + " NOT NULL" /* selection */,
            new String[] { ImApp.IMPS_CATEGORY } /* selection args */, Imps.Provider.DEFAULT_SORT_ORDER);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item,
            mCursorProviders, new String[] { Imps.Provider.ACTIVE_ACCOUNT_USERNAME },
            new int[] { android.R.id.text1 });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // TODO Something is causing the managedQuery() to return null, use null guard for now
    if (mCursorProviders != null && mCursorProviders.getCount() > 0) {
        mCursorProviders.moveToFirst();//w  ww. j  a va  2 s . co  m
        mProviderId = mCursorProviders.getLong(PROVIDER_ID_COLUMN);
        mAccountId = mCursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
    }

    mListSpinner.setAdapter(adapter);
    mListSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (mCursorProviders == null)
                return;
            mCursorProviders.moveToPosition(arg2);
            mProviderId = mCursorProviders.getLong(PROVIDER_ID_COLUMN);
            mAccountId = mCursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

}

From source file:com.heneryh.aquanotes.ui.feed.FeedActivity.java

private void fillSpinner() {

    Uri controllersQueryUri = Controllers.buildQueryControllersUri();
    Cursor cursor = dbResolverFeedAct.query(controllersQueryUri, ControllersQuery.PROJECTION, null, null, null);

    startManagingCursor(cursor);/*from  w  w w  .  jav a2 s . c  om*/

    // create an array to specify which fields we want to display
    String[] from = new String[] { ControllersQuery.PROJECTION[ControllersQuery.TITLE] };
    // create an array of the display item we want to bind our data to
    int[] to = new int[] { android.R.id.text1 };
    // create simple cursor adapter
    @SuppressWarnings("deprecation")
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor,
            from, to);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // get reference to our spinner
    Spinner s = (Spinner) findViewById(R.id.ctrlr_id);
    s.setAdapter(adapter);
}

From source file:com.piusvelte.wapdroid.ManageData.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    SimpleCursorAdapter adapter;/*  www. j  av a  2 s.  c o m*/

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        adapter = new SimpleCursorAdapter(getActivity(), R.layout.network_row, null,
                new String[] { Networks.SSID, Networks.BSSID, STATUS, Networks.MANAGE },
                new int[] { R.id.network_row_SSID, R.id.network_row_BSSID, R.id.network_row_status,
                        R.id.network_manage });
    } else {
        adapter = new SimpleCursorAdapter(getActivity(), R.layout.network_row, null,
                new String[] { Networks.SSID, Networks.BSSID, STATUS, Networks.MANAGE },
                new int[] { R.id.network_row_SSID, R.id.network_row_BSSID, R.id.network_row_status,
                        R.id.network_manage },
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    }

    adapter.setViewBinder(mViewBinder);
    setListAdapter(adapter);
    getLoaderManager().initLoader(DATA_LOADER, getCursorArguments(), this);
}

From source file:liqui.droid.activity.LiquiDroid.java

@SuppressWarnings("deprecation")
@Override/*w w  w . j a  v a 2 s .c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getIntent().getAction() != null
            && getIntent().getAction().equals(getString(R.string.action_login_sync))) {
        // we create a new account
    } else {
        Cursor c = getContentResolver().query(ACCOUNT_CONTENT_URI, null, "last_active = 1", null, null);

        c.moveToFirst();

        if (!c.isAfterLast()) {
            mApiName = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_NAME));
            mApiUrl = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_URL));
            mMemberId = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_MEMBER_ID));
            mSessionKey = c.getString(c.getColumnIndex(DBSystem.Account.COLUMN_SESSION_KEY));

            Log.d("XXX", "loading old session: " + mMemberId + "@" + mApiName);
        }

        c.close();
    }

    if (isAuthenticated()) {
        Intent intent = new Intent().setClass(LiquiDroid.this, MemberActivity.class);

        Bundle extras = new Bundle();
        extras.putString(Constants.Account.API_NAME, getAPIName());
        extras.putString(Constants.Account.API_URL, getAPIUrl());
        extras.putString(Constants.Account.MEMBER_ID, getMemberId());
        extras.putString(Constants.Account.SESSION_KEY, getSessionKey());
        intent.putExtras(extras);

        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);

        finish();
        return;
    }

    setContentView(R.layout.act_main);

    /*
    ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
            
    actionBar.addAction(new IntentAction(this, new Intent(getApplicationContext(),
        Search.class), R.drawable.ic_search));
                
        */

    mSpinnerLQFBs = (Spinner) findViewById(R.id.sp_lqfb_instance);

    mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, null,
            new String[] { DBSystem.Instance.COLUMN_NAME, DBSystem.Instance.COLUMN_ID },
            new int[] { android.R.id.text1 });

    mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    mSpinnerLQFBs.setAdapter(mAdapter);
    mSpinnerLQFBs.setOnItemSelectedListener(this);

    mEditTextApiKey = (EditText) findViewById(R.id.et_api_token);
    mEditTextApiKey.addTextChangedListener(mPasswortTextWatcher);

    mButtonLogin = (Button) findViewById(R.id.btn_login);
    mButtonLogin.setEnabled(false);
    mButtonLogin.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Cursor c = (Cursor) mSpinnerLQFBs.getSelectedItem();

            if (c == null)
                return;

            mApiUrl = c.getString(c.getColumnIndex(DBSystem.Instance.COLUMN_URL));
            mApiName = c.getString(c.getColumnIndex(DBSystem.Instance.COLUMN_NAME));

            hideKeyboard(mButtonLogin.getWindowToken());

            String key = mEditTextApiKey.getText().toString().trim();
            new LoginTask(LiquiDroid.this).execute(getAPIName(), getAPIUrl(), key);
        }
    });

    TextView tvExplore = (TextView) findViewById(R.id.tv_explore);
    tvExplore.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent().setClass(LiquiDroid.this, Explore.class);

            Bundle extras = new Bundle();
            extras.putString(Constants.Account.API_NAME, mApiName);
            extras.putString(Constants.Account.API_URL, mApiUrl);
            extras.putString(Constants.Account.MEMBER_ID, mMemberId);
            extras.putString(Constants.Account.SESSION_KEY, mSessionKey);
            intent.putExtras(extras);

            startActivity(intent);
        }
    });

    if (getIntent().getAction() != null
            && getIntent().getAction().equals(getString(R.string.action_login_sync))) {
        // we create a new account

        LinearLayout llExplore = (LinearLayout) findViewById(R.id.ll_explore);
        llExplore.setVisibility(View.GONE);
    }

    getSupportLoaderManager().initLoader(0, null, this);
}

From source file:com.dmsl.anyplace.SearchPOIActivity.java

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        // get the search type
        mSearchType = (SearchTypes) intent.getSerializableExtra("searchType");
        if (mSearchType == null)
            finishSearch("No search type provided!", null);

        // get the query string
        final String query = intent.getStringExtra("query");
        double lat = intent.getDoubleExtra("lat", 0);
        double lng = intent.getDoubleExtra("lng", 0);

        AnyplaceSuggestionsTask mSuggestionsTask = new AnyplaceSuggestionsTask(
                new AnyplaceSuggestionsTask.AnyplaceSuggestionsListener() {

                    @Override//w  w  w. j  a v a2 s. c o  m
                    public void onSuccess(String result, List<? extends IPoisClass> pois) {

                        // we have pois to query for a match
                        mQueriedPoisStr = new ArrayList<Spanned>();
                        mQueriedPois = pois;

                        // Display part of Description Text Only
                        // Make an approximation of available space based on map size
                        final int viewWidth = (int) (findViewById(R.id.txtResultsFound).getWidth() * 2);
                        View infoWindow = getLayoutInflater()
                                .inflate(R.layout.queried_pois_item_1_searchactivity, null);
                        TextView infoSnippet = (TextView) infoWindow;
                        TextPaint paint = infoSnippet.getPaint();

                        // Regular expression
                        // ?i ignore case
                        Pattern pattern = Pattern.compile(String.format("((?i)%s)", query));

                        for (IPoisClass pm : pois) {
                            String name = "", description = "";
                            Matcher m;
                            m = pattern.matcher(pm.name());
                            // Makes matched query bold using HTML format
                            // $1 returns the regular's expression outer parenthesis value
                            name = m.replaceAll("<b>$1</b>");

                            m = pattern.matcher(pm.description());
                            if (m.find()) {
                                // Makes matched query bold using HTML format
                                // $1 returns the regular's expression outer parenthesis value
                                int startIndex = m.start();
                                description = m.replaceAll("<b>$1</b>");
                                description = AndroidUtils.fillTextBox(paint, viewWidth, description,
                                        startIndex + 3);
                            }
                            mQueriedPoisStr.add(Html.fromHtml(name + "<br>" + description));
                        }

                        ArrayAdapter<Spanned> mAdapter = new ArrayAdapter<Spanned>(
                                // getBaseContext(), R.layout.queried_pois_item_1,
                                getBaseContext(), R.layout.queried_pois_item_1_searchactivity, mQueriedPoisStr);
                        lvResultPois.setAdapter(mAdapter);
                        txtResultsFound.setText("Results found [ " + mQueriedPoisStr.size() + " ]");

                    }

                    @Override
                    public void onErrorOrCancel(String result) {
                        // no pois exist
                        finishSearch("No Points of Interest exist!", null);
                    }

                    @Override
                    public void onUpdateStatus(String string, Cursor cursor) {
                        SimpleCursorAdapter adapter = new SimpleCursorAdapter(getBaseContext(),
                                R.layout.queried_pois_item_1_searchactivity, cursor,
                                new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 },
                                new int[] { android.R.id.text1 });
                        lvResultPois.setAdapter(adapter);
                        txtResultsFound.setText("Results found [ " + cursor.getCount() + " ]");
                    }

                }, this, mSearchType, new GeoPoint(lat, lng), query);
        mSuggestionsTask.execute();

    }
}

From source file:org.awesomeapp.messenger.ui.AddContactActivity.java

private void setupAccountSpinner() {
    final Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT;

    mCursorProviders = managedQuery(uri, PROVIDER_PROJECTION,
            Imps.Provider.CATEGORY + "=?" + " AND " + Imps.Provider.ACTIVE_ACCOUNT_USERNAME
                    + " NOT NULL" /* selection */,
            new String[] { ImApp.IMPS_CATEGORY } /* selection args */, Imps.Provider.DEFAULT_SORT_ORDER);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item,
            mCursorProviders, new String[] { Imps.Provider.ACTIVE_ACCOUNT_USERNAME },
            new int[] { android.R.id.text1 });
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // TODO Something is causing the managedQuery() to return null, use null guard for now
    if (mCursorProviders != null && mCursorProviders.getCount() > 0) {
        mCursorProviders.moveToFirst();/*from w ww  .  ja va2  s. c o  m*/
        mProviderId = mCursorProviders.getLong(PROVIDER_ID_COLUMN);
        mAccountId = mCursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
    }

    /**
    mListSpinner.setAdapter(adapter);
    mListSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,
            int arg2, long arg3) {
        if (mCursorProviders == null)
            return;
        mCursorProviders.moveToPosition(arg2);
        mProviderId = mCursorProviders.getLong(PROVIDER_ID_COLUMN);
        mAccountId = mCursorProviders.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
     }
            
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
            
    }
    });
    */
}

From source file:com.groundupworks.wings.facebook.FacebookAlbumListFragment.java

/**
 * Asynchronously requests the albums associated with the linked account. Sets the {@link ListAdapter} when
 * completed.//  w w  w  . ja v a  2s .  c om
 *
 * @param pageAlbums a list of page albums associated with Page accounts.
 */
private void requestAlbums(final List<Object[]> pageAlbums) {
    Callback callback = new Callback() {
        @Override
        public void onCompleted(Response response) {
            FacebookSettingsActivity activity = (FacebookSettingsActivity) getActivity();
            if (activity == null || activity.isFinishing()) {
                return;
            }

            if (response != null && response.getError() == null) {
                Object[] appAlbum = null;
                List<Object[]> albums = new ArrayList<Object[]>();

                GraphObject graphObject = response.getGraphObject();
                if (graphObject != null) {
                    JSONObject jsonObject = graphObject.getInnerJSONObject();
                    try {
                        JSONArray jsonArray = jsonObject
                                .getJSONArray(FacebookEndpoint.ALBUMS_LISTING_RESULT_DATA_KEY);
                        long cursorId = 1L + pageAlbums.size();
                        for (int i = 0; i < jsonArray.length(); i++) {
                            try {
                                // Get data from json.
                                JSONObject album = jsonArray.getJSONObject(i);
                                String id = album.getString(FacebookEndpoint.ALBUMS_LISTING_FIELD_ID);
                                String name = album.getString(FacebookEndpoint.ALBUMS_LISTING_FIELD_NAME);
                                String type = album.getString(FacebookEndpoint.ALBUMS_LISTING_FIELD_TYPE);
                                String privacy = album.getString(FacebookEndpoint.ALBUMS_LISTING_FIELD_PRIVACY);
                                boolean canUpload = album
                                        .getBoolean(FacebookEndpoint.ALBUMS_LISTING_FIELD_CAN_UPLOAD);

                                // Filter out albums that do not allow upload.
                                if (canUpload && id != null && id.length() > 0 && name != null
                                        && name.length() > 0 && type != null && type.length() > 0
                                        && privacy != null && privacy.length() > 0) {
                                    String graphPath = id + FacebookEndpoint.ALBUM_ID_TO_GRAPH_PATH;
                                    if (FacebookEndpoint.DEFAULT_ALBUM_TYPE.equals(type)) {
                                        appAlbum = new Object[] { APP_ALBUM_CURSOR_ID,
                                                FacebookEndpoint.DestinationId.PROFILE, name, graphPath,
                                                FacebookEndpoint.APP_ALBUM_PRIVACY, null };
                                    } else {
                                        albums.add(
                                                new Object[] { cursorId, FacebookEndpoint.DestinationId.PROFILE,
                                                        name, graphPath, privacy, null });
                                        cursorId++;
                                    }
                                }
                            } catch (JSONException e) {
                                // Do nothing.
                            }
                        }
                    } catch (JSONException e) {
                        // Do nothing.
                    }
                }

                // If not already present, construct row to represent the default app album that will be auto
                // created.
                if (appAlbum == null) {
                    appAlbum = new Object[] { APP_ALBUM_CURSOR_ID, FacebookEndpoint.DestinationId.PROFILE,
                            activity.getString(R.string.wings_facebook__app_album_default_name),
                            FacebookEndpoint.APP_ALBUM_GRAPH_PATH, FacebookEndpoint.APP_ALBUM_PRIVACY, null };
                }

                // Construct matrix cursor.
                mAlbumCursor.addRow(appAlbum);
                for (Object[] pageAlbum : pageAlbums) {
                    mAlbumCursor.addRow(pageAlbum);
                }
                for (Object[] album : albums) {
                    mAlbumCursor.addRow(album);
                }

                // Set adapter.
                setListAdapter(new SimpleCursorAdapter(activity, R.layout.facebook_album_list_view_item,
                        mAlbumCursor, new String[] { CURSOR_ALBUM_NAME, CURSOR_ALBUM_PRIVACY },
                        new int[] { R.id.album_name, R.id.album_privacy }));
            } else {
                // Finish Activity with error.
                activity.mHasErrorOccurred = true;
                activity.tryFinish();
            }
        }
    };

    mFacebookEndpoint.requestAlbums(callback);
}

From source file:com.kncwallet.wallet.ui.SendCoinsFragment.java

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

    final View view = inflater.inflate(R.layout.send_coins_fragment, container, false);
    contactsListView = (ListView) view.findViewById(R.id.send_coins_contacts_list);

    viewBalanceBtc = (CurrencyTextView) view.findViewById(R.id.wallet_balance_btc);

    txText = (EditText) view.findViewById(R.id.send_coins_text);

    viewBalanceLocal = (CurrencyTextView) view.findViewById(R.id.wallet_balance_local);

    viewBalanceLocal.setPrecision(Constants.LOCAL_PRECISION, 0);
    viewBalanceLocal.setStrikeThru(Constants.TEST);

    viewBalanceBtc.setOnClickListener(new OnClickListener() {
        @Override//w w  w.  j  a v  a 2  s.  co m
        public void onClick(final View v) {
            SendCoinsFragment.this.switchBalance();
        }
    });

    viewBalanceLocal.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            SendCoinsFragment.this.switchBalance();
        }
    });

    receivingAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_coins_receiving_address);
    receivingAddressView.setAdapter(new AutoCompleteAddressAdapter(activity, null));
    receivingAddressView.setOnFocusChangeListener(receivingAddressListener);
    receivingAddressView.addTextChangedListener(receivingAddressListener);

    receivingStaticView = view.findViewById(R.id.send_coins_receiving_static);
    receivingStaticAddressView = (TextView) view.findViewById(R.id.send_coins_receiving_static_address);
    receivingStaticLabelView = (TextView) view.findViewById(R.id.send_coins_receiving_static_label);

    receivingStaticView.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {

            if (hasFocus) {
                startReceivingAddressActionMode();
            } else {
                clearActionMode();
            }
        }
    });

    btcAmountView = (CurrencyAmountView) view.findViewById(R.id.send_coins_amount_btc);
    btcAmountView.setCurrencySymbol(DenominationUtil.getCurrencyCode(btcShift));
    btcAmountView.setInputPrecision(DenominationUtil.getMaxPrecision(btcShift));
    btcAmountView.setHintPrecision(btcPrecision);
    btcAmountView.setShift(btcShift);

    final CurrencyAmountView localAmountView = (CurrencyAmountView) view
            .findViewById(R.id.send_coins_amount_local);
    localAmountView.setInputPrecision(Constants.LOCAL_PRECISION);
    localAmountView.setHintPrecision(Constants.LOCAL_PRECISION);
    amountCalculatorLink = new CurrencyCalculatorLink(btcAmountView, localAmountView);

    bluetoothEnableView = (CheckBox) view.findViewById(R.id.send_coins_bluetooth_enable);
    bluetoothEnableView.setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled());
    bluetoothEnableView.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
            if (isChecked && !bluetoothAdapter.isEnabled()) {
                // try to enable bluetooth
                startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),
                        REQUEST_CODE_ENABLE_BLUETOOTH);
            }
        }
    });

    bluetoothMessageView = (TextView) view.findViewById(R.id.send_coins_bluetooth_message);

    sentTransactionView = (ListView) view.findViewById(R.id.send_coins_sent_transaction);
    sentTransactionListAdapter = new TransactionsListAdapter(activity, wallet, application.maxConnectedPeers(),
            false);
    sentTransactionView.setAdapter(sentTransactionListAdapter);

    viewGo = (Button) view.findViewById(R.id.send_coins_go);
    viewGo.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            validateReceivingAddress(true);
            validateAmounts(true);

            if (everythingValid())
                handleGo();
        }
    });

    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    } else {
        final Intent intent = activity.getIntent();
        final String action = intent.getAction();
        final Uri intentUri = intent.getData();
        final String scheme = intentUri != null ? intentUri.getScheme() : null;

        if ((Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && intentUri != null && "bitcoin".equals(scheme))
            initStateFromBitcoinUri(intentUri);
        else if (intent.hasExtra(SendCoinsFragment.INTENT_EXTRA_ADDRESS))
            initStateFromIntentExtras(intent.getExtras());
    }

    TextView header = ((TextView) view.findViewById(R.id.header_text));

    header.setText(R.string.send_heading);

    contactListAdapter = new SimpleCursorAdapter(activity, R.layout.address_book_row_small, null,
            new String[] { AddressBookProvider.KEY_ADDRESS, AddressBookProvider.KEY_LABEL,
                    AddressBookProvider.KEY_ADDRESS, AddressBookProvider.KEY_ADDRESS },
            new int[] { R.id.address_book_contact_image, R.id.address_book_row_label,
                    R.id.address_book_row_address, R.id.address_book_row_source_image });

    contactListAdapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
            if (view.getId() == R.id.address_book_contact_image) {
                //...
                SmartImageView img = (SmartImageView) view;
                //img.setImageBitmap(bm);
                String address = cursor.getString(columnIndex);
                Bitmap contactImage = AddressBookProvider.bitmapForAddress(SendCoinsFragment.this.getActivity(),
                        address);
                if (contactImage != null) {
                    img.setImageBitmap(contactImage);
                } else {

                    String imageUrl = ContactImage.getImageUrl(activity,
                            AddressBookProvider.resolveRowId(activity, address));
                    if (imageUrl != null) {
                        img.setImageUrl(imageUrl, R.drawable.contact_placeholder);
                    } else {
                        img.setImageResource(R.drawable.contact_placeholder);
                    }

                }

                return true; //true because the data was bound to the view
            } else if (view.getId() == R.id.address_book_row_source_image) {
                ((ImageView) view).setImageResource(cachedSourceImageResource(cursor.getString(columnIndex)));
                return true;
            }

            //Constants.ADDRESS_FORMAT_LINE_SIZE));

            return false;
        }
    });

    boolean smallScreen = getResources().getBoolean(R.bool.values_small);

    if (!smallScreen) {
        ListView list = (ListView) contactsListView;
        Drawable divider = getResources().getDrawable(R.drawable.transaction_list_divider);
        list.setDivider(divider);
        list.setDividerHeight(1);
        list.setAdapter(contactListAdapter);

        list.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                //to save a lookup
                TextView addr = (TextView) view.findViewById(R.id.address_book_row_address);
                TextView label = (TextView) view.findViewById(R.id.address_book_row_label);

                if (setSendAddress(addr.getText().toString(), label.getText().toString())) {
                    startReceivingAddressActionMode();
                } else {
                    informInvalidAddress(addr.getText().toString(), label.getText().toString());
                }

            }
        });
    } else {
        contactsListView.setVisibility(View.GONE);
    }

    return view;
}

From source file:com.gigabytedevelopersinc.app.calculator.Calculator.java

void fillData() {
    Cursor c = dbAdapter.fetchAllMemories();
    startManagingCursor(c);//from  w ww  .  j  a va 2s.co  m

    String[] from = new String[] { DbAdapter.KEY_EXP, DbAdapter.KEY_RESULT };
    int[] to = new int[] { R.id.text1, R.id.text2 };

    SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.history_row, c, from, to);
    memoryList.setAdapter(notes);
    registerForContextMenu(memoryList);

    memoryList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            view.showContextMenu();
        }
    });

    c = dbAdapter.fetchAllHistories();
    startManagingCursor(c);

    from = new String[] { DbAdapter.KEY_EXP, DbAdapter.KEY_RESULT };
    to = new int[] { R.id.text1, R.id.text2 };

    notes = new SimpleCursorAdapter(this, R.layout.history_row, c, from, to);
    historyList.setAdapter(notes);
    registerForContextMenu(historyList);

    historyList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            view.showContextMenu();
        }
    });

    try {
        if (page_no == 2)
            c = dbAdapter.fetchAllFavs(1);
        else
            c = dbAdapter.fetchAllFavs(2);
        startManagingCursor(c);

        from = new String[] { DbAdapter.KEY_EXP, DbAdapter.KEY_RESULT };
        to = new int[] { R.id.text1, R.id.text2 };

        notes = new SimpleCursorAdapter(this, R.layout.history_row, c, from, to);
        favList.setAdapter(notes);
        registerForContextMenu(favList);

        favList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                view.showContextMenu();
            }
        });
    } catch (Exception exe) {
        //
    }
}