mardi 27 octobre 2015

Edit text from SQLite before it gets passed through to the display

Hi I would like to change the text that will be displayed after I pull it from the database depending on a condition:

From the code I think you will be able to see what i want to do, I just cant figure out how, I learnt android from a tutorial so I only know what I learned there, well for now.

I just simply want to add a "+" or "-" in front of the text being pulled from the db, depending on another field in the result.

Here is what i have tried but it crashes(it doesnt work without the .toString() aswell):

final Button btnall = (Button) findViewById(R.id.btnAll);
    btnall.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Cursor cursor = mDbAdapter.fetchAllbets();
            String jimbo = BetDbAdapter.COL_OUTCOME.toString();
            String end = "";
            if(jimbo.trim().equalsIgnoreCase("W"))
            {
                end= "+ "+BetDbAdapter.COL_RESULT.toString();
            }
            else
            {
                end= "- "+BetDbAdapter.COL_RESULT.toString();
            }
            String[] from = new String[]{
                    BetDbAdapter.COL_OUTCOME,
                    BetDbAdapter.COL_PLACED,
                    end
            };
            int[] to = new int[]{
                    R.id.won_lost,
                    R.id.row_text,
                    R.id.loss_pro
            };
            mCursorAdapter = new BetSimpleCursorAdapter(Betting.this, R.layout.betting_row, cursor, from, to, 0);
            mListView.setAdapter(mCursorAdapter);
        }
    });

Before I posted the question, I took a brief relook over the app and B think B am trying to change stuff in the wrong area of the app, just tell me if thats correct or am I in the right area? This code is in the oncreate method.

Aucun commentaire:

Enregistrer un commentaire