0

I'm trying to open a form based on the value of the Expense field being Null.
if in my app one of my list items, one of the expense items has a value of Null
i want it to open a certain form.
If it contains a value of "1" I want it to open a different form.

Can someone take a look at my code to se where I might be going wrong.

private void fillData() {
            mItemsCursor = mDbHelper.fetchAllItems();
    startManagingCursor(mItemsCursor);

            String[] from = new String[]{DbAdapter.KEY_ITEM, DbAdapter.KEY_EXPENSE, DbAdapter.KEY_BUDGET,
            DbAdapter.KEY_ACTUAL, DbAdapter.KEY_RESULTS};


    int[] to = new int[]{R.id.text1, R.id.text2, R.id.text3, R.id.text4, R.id.text5};


            SimpleCursorAdapter items = 
        new SimpleCursorAdapter(this, R.layout.budget_row, mItemsCursor, from, to);
    setListAdapter(items);
}   

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id); 
    if (DbAdapter.KEY_EXPENSE == null) {
        Intent i = new Intent(this, Budget_Income.class);
        i.putExtra(DbAdapter.KEY_ROWID, id);        
        startActivityForResult(i, ACTIVITY_EDIT);
    }
    else {
        Intent a = new Intent(this, Budget_Expense.class);
        a.putExtra(DbAdapter.KEY_ROWID, id);        
        startActivityForResult(a, ACTIVITY_EDIT);
    }


}
wwarren07
  • 17
  • 9
  • can you describe what exactly is going wrong and where? What error messages? Logcat output? – Martin Aug 30 '13 at 21:35
  • `DbAdapter.KEY_EXPENSE == null` checks your *key* for null, not the *value* (assuming you worked with regular java and android conventions for variable names). You probably want to check the value in a `List> values` you inserted into an `ArrayAdapter` or something (`position` is the index of the row tapped). In that case: `values.get(position).get(DbAdapter.KEY_EXPENSE)` is probably more suitable... – dst Aug 30 '13 at 21:38
  • when i select the item, it's only firing the activity for the budget_Expense.class. No matter if the KEY_EXPENSE is null or not. – wwarren07 Aug 30 '13 at 22:22
  • @dst Do I replace the (DbAdapter.KEY_EXPENSE == null) with your suggestion? I'm getting an error on the values, telling me to make it a vaiable. – wwarren07 Sep 04 '13 at 11:53
  • No! I did not suggest concrete code for your specific example, I tried to explain the general issue. For your specific case, have a look at http://stackoverflow.com/questions/5376860/how-to-get-string-from-selected-item-of-simplecursoradapter – dst Sep 04 '13 at 14:07

1 Answers1

0

is this DbAdapter.KEY_EXPENSE a constant (static and final)? If it is and it is assigned to null you will always enter inside that part of the if statement.

nakov
  • 13,938
  • 12
  • 60
  • 110
  • No it is no. it is coming from another method. See my update to my code. Method fillData() – wwarren07 Aug 30 '13 at 21:41
  • yes, as dst said above in the comments, you are trying to compare the column name with a null value. you should check the value of that column instead. Ex. mItemsCursor.get(position) will give you the row from your table, then you search for the column (DBAdapter.KEY_EXPENSE) value and compare it to null or whatever – nakov Sep 01 '13 at 07:22