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

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

Introduction

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

Prototype

public void setViewBinder(ViewBinder viewBinder) 

Source Link

Document

Sets the binder used to bind data to views.

Usage

From source file:fr.eoidb.activity.fragment.ItemMaterialListFragment.java

@Override
protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) {
    adapter.setViewBinder(new ItemListViewBinder());
    adapter.swapCursor(cursor);//from  w  w  w. j  a  v  a 2s  . c  o m
}

From source file:fr.eoit.activity.fragment.ItemMaterialListFragment.java

@Override
protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) {
    adapter.setViewBinder(new ItemListViewBinder(behavior));
    adapter.swapCursor(cursor);//from  w  w  w.  j  a  v  a  2 s.co  m
}

From source file:fr.eoit.activity.fragment.blueprint.RequiredItemsBlueprintCopyInventionFragment.java

@Override
protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) {
    adapter.setViewBinder(new RequiredItemListViewBinder(RedQuantityBehavior.NONE, fragmentReference));
    adapter.swapCursor(cursor);//  w w  w  .ja  va 2 s.  c  o  m
}

From source file:fr.eoidb.activity.fragment.EnhancedMaterialListFragment.java

@Override
protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) {
    super.onLoadFinishedAdapteur(cursor, adapter);
    adapter.setViewBinder(new MaterialsListViewBinderWithTotalPriceAndVolume());
}

From source file:de.hshannover.f4.trust.ironcontrol.view.list_activities.ListResponsesActivity.java

@Override
protected SimpleCursorAdapter setListAdapter(ListHierarchyType type) {
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.responses_list_row, null,
            FROM_RESPONSES, TO_LIST2_ROW, 0);
    adapter.setViewBinder(buildViewBinder());
    return adapter;
}

From source file:ibme.sleepap.history.ViewHistory.java

/** Called when the activity is first created. */
@Override/* www . ja v  a2s  .  c  o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_history);

    dbHelper = new DatabaseHelper(this);
    database = dbHelper.getWritableDatabase();

    Cursor cursor = database.query(HistoryTable.TABLE_NAME, HistoryTable.ALL_COLUMNS, null, null, null, null,
            HistoryTable.COLUMN_START_DATE);
    String[] fromColumns = { HistoryTable.COLUMN_START_DATE_DISPLAY, HistoryTable.COLUMN_ODI,
            HistoryTable.COLUMN_QUESTIONNAIRE, HistoryTable.COLUMN_SVM_RESULT };
    int[] toViews = { R.id.date, R.id.odi, R.id.questionnaire, R.id.svm };

    if (cursor.getCount() > 0) {
        findViewById(R.id.noHistoryFound).setVisibility(View.GONE);

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.history_item, cursor, fromColumns,
                toViews, 0);

        adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                TextView textView = (TextView) view;
                String name = cursor.getColumnName(columnIndex);
                if (name.equals(HistoryTable.COLUMN_ODI)) {
                    String odi = cursor.getString(columnIndex);
                    textView.setText(odi);
                    if (odi.equals("-")) {
                        return true;
                    }
                    float odival = Float.parseFloat(odi);
                    int color;
                    if (odival < 5) {
                        color = 0xFF00FF00;
                    } else {
                        color = 0xFFFF0000;
                    }
                    textView.setTextColor(color);
                    return true;
                }
                if (name.equals(HistoryTable.COLUMN_QUESTIONNAIRE)) {
                    String stopBangScore = cursor.getString(columnIndex);
                    textView.setText(stopBangScore);
                    if (stopBangScore.equals("-")) {
                        return true;
                    }
                    int stopBangScoreVal = Integer.parseInt(stopBangScore);
                    int color;
                    if (stopBangScoreVal < 3) {
                        color = 0xFF00FF00;
                    } else {
                        color = 0xFFFF0000;
                    }
                    textView.setTextColor(color);
                    return true;
                }
                if (name.equals(HistoryTable.COLUMN_SVM_RESULT)) {
                    String svmScore = cursor.getString(columnIndex);
                    if (svmScore.equals("-")) {
                        textView.setText(svmScore);
                        return true;
                    }
                    Float stopBangScoreVal = Float.parseFloat(svmScore);
                    textView.setText(String.format("%.0f%%", stopBangScoreVal * 100));
                    int color;
                    if (stopBangScoreVal < 0.5) {
                        color = 0xFF00FF00;
                    } else {
                        color = 0xFFFF0000;
                    }
                    textView.setTextColor(color);
                    return true;
                }
                return false;
            }
        });

        ListView listView = (ListView) findViewById(R.id.historyList);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(ViewHistory.this, ViewAnalysis.class);
                intent.putExtra(Constants.EXTRA_RECORDING_ID, id);
                startActivity(intent);
                overridePendingTransition(R.anim.enteringfromright, R.anim.exitingtoleft);
            }
        });
    } else {
        findViewById(R.id.columnHeadings).setVisibility(View.GONE);
    }
}

From source file:org.onebusaway.android.ui.MyRemindersFragment.java

private SimpleCursorAdapter newAdapter() {
    final String[] from = { ObaContract.Trips.NAME, ObaContract.Trips.HEADSIGN, ObaContract.Trips.DEPARTURE,
            ObaContract.Trips.ROUTE_ID };
    final int[] to = { R.id.name, R.id.headsign, R.id.departure_time, R.id.route_name };
    SimpleCursorAdapter simpleAdapter = new SimpleCursorAdapter(getActivity(), R.layout.trip_list_listitem,
            null, from, to, 0);//from  ww w.ja  v  a2 s .c  o m

    simpleAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (columnIndex == COL_NAME) {
                TextView text = (TextView) view;
                String name = cursor.getString(columnIndex);
                if (name.length() == 0) {
                    name = getString(R.string.trip_info_noname);
                }
                text.setText(name);
                return true;
            } else if (columnIndex == COL_HEADSIGN) {
                String headSign = cursor.getString(columnIndex);
                TextView text = (TextView) view;
                text.setText(MyTextUtils.toTitleCase(headSign));
                return true;
            } else if (columnIndex == COL_DEPARTURE) {
                TextView text = (TextView) view;
                text.setText(TripInfoActivity.getDepartureTime(getActivity(),
                        ObaContract.Trips.convertDBToTime(cursor.getInt(columnIndex))));
                return true;
            } else if (columnIndex == COL_ROUTE_ID) {
                //
                // Translate the Route ID into the Route Name by looking
                // it up in the Routes table.
                //
                TextView text = (TextView) view;
                final String routeId = cursor.getString(columnIndex);
                final String routeName = TripService.getRouteShortName(getActivity(), routeId);
                if (routeName != null) {
                    text.setText(getString(R.string.trip_info_route, routeName));
                }
                return true;
            }
            return false;
        }
    });
    return simpleAdapter;
}

From source file:de.hshannover.f4.trust.ironcontrol.view.list_activities.ListOverviewActivity.java

@Override
protected SimpleCursorAdapter setListAdapter(ListHierarchyType type) {
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.search_list_row, null, FROM_REQUESTS,
            TO_LIST1_ROW, 0);//from w  ww .  j a  v a  2 s.co m
    switch (type) {
    case SEARCH:
        break;
    case SUBSCRIPTION:
        adapter.setViewBinder(buildViewBinder());
        break;
    }
    return adapter;
}

From source file:com.svpino.longhorn.activities.DashboardActivity.java

private void performSearch(String query) {
    this.stockListFragment.hideContextualActionBar();
    Cursor cursor = DataProvider.search(getApplicationContext(), query);

    if (this.searchDialog == null || !this.searchDialog.isShowing()) {
        this.searchDialog = new Dialog(this);
        this.searchDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.searchDialog.setContentView(R.layout.dialog);

        TextView messageTextView = (TextView) this.searchDialog.findViewById(R.id.messageTextView);
        TextView titleTextView = (TextView) this.searchDialog.findViewById(R.id.titleTextView);

        ListView listView = (ListView) this.searchDialog.findViewById(R.id.listView);

        if (cursor != null && cursor.getCount() > 0) {
            titleTextView.setText(String.format(getString(R.string.dialog_search_title), query));
            messageTextView.setVisibility(View.GONE);

            String[] from = new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1,
                    SearchManager.SUGGEST_COLUMN_TEXT_2, LonghornDatabase.KEY_EXCHANGE_SYMBOL };
            int[] to = new int[] { R.id.nameTextView, R.id.descriptionTextView, R.id.additionalTextView };

            SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.dialog_item,
                    cursor, from, to, 0);
            adapter.setViewBinder(new ViewBinder() {

                @Override//w w  w  .  ja v  a  2 s  .co m
                public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

                    if (columnIndex == 0) {
                        ((View) view.getParent()).setTag(cursor.getString(columnIndex));
                    }

                    return false;
                }
            });

            listView.setAdapter(adapter);

            listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                    Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
                    addStockToWatchList(cursor.getString(0));
                    DashboardActivity.this.searchDialog.dismiss();
                }
            });
        } else {
            titleTextView.setText(getString(R.string.dialog_search_empty_title));
            messageTextView.setText(String.format(getString(R.string.dialog_search_empty_message), query));
            messageTextView.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
        }

        this.searchDialog.show();
    }
}

From source file:com.wheelly.fragments.LocationsListFragment.java

private ListAdapter buildAdapter() {
    if (inSelectMode) {
        return new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_single_choice, null,
                new String[] { "name" }, new int[] { android.R.id.text1 }, 0) {
            {/*from   w ww. j a  va  2s .co  m*/
                setViewBinder(new ViewBinder() {
                    @Override
                    public boolean setViewValue(View view, Cursor cursor, int paramInt) {
                        if (android.R.id.text1 == view.getId()) {
                            final String argb = cursor.getString(cursor.getColumnIndex("color"));
                            if (!Strings.isNullOrEmpty(argb)) {
                                view.setBackgroundColor(Color.parseColor(argb));
                            }
                        }
                        return false;
                    }
                });
            }
        };
    }

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.location_item, null,
            new String[] { "name", "resolved_address", "name" },
            new int[] { android.R.id.text1, android.R.id.text2, R.id.text3 }, 0);

    adapter.setViewBinder(new LocationViewBinder(null));

    LocationUtils.obtainLocation(getActivity(), new LocationListener() {
        @Override
        public void onLocationChanged(Location paramLocation) {
            ((LocationViewBinder) adapter.getViewBinder()).location = paramLocation;
            adapter.notifyDataSetChanged();
        }
    });

    return adapter;
}