Hi,
I have this simple activity with custom row that contains CheckBox and 3
TextView s.
Here is my activity:
*****************************************************************************************************
public class AllRatesActivity extends ListActivity
{
ExchangeRatesApplication exchangeRatesApplication;
static ExchangeRatesData ratesData;
Cursor cursor;
ListView listRates;
SimpleCursorAdapter adapter;
static final String[] FROM = { ExchangeRatesData.C_SHORT_NAME,
ExchangeRatesData.C_NAME, ExchangeRatesData.C_RATE,
ExchangeRatesData.C_SELECTED };
static final int[] TO = { R.id.shortName, R.id.name, R.id.exchangeRate,
R.id.selectedBox };
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.all_rates);
exchangeRatesApplication = (ExchangeRatesApplication) getApplication();
ratesData = new ExchangeRatesData(this);
listRates = this.getListView();
}
@Override
protected void onDestroy()
{
super.onDestroy();
ratesData.close();
}
@Override
protected void onResume()
{
super.onResume();
this.setupList();
}
private void setupList()
{
cursor = ratesData.getAllRates();
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, FROM, TO);
adapter.setViewBinder(VIEW_BINDER);
listRates.setAdapter(adapter);
}
static final ViewBinder VIEW_BINDER = new ViewBinder()
{
public boolean setViewValue(View view, Cursor cursor, int columnIndex)
{
if (view.getId() == R.id.exchangeRate)
{
String rate =
cursor.getString(cursor.getColumnIndex(ExchangeRatesData.C_RATE));
String amount =
cursor.getString(cursor.getColumnIndex(ExchangeRatesData.C_AMOUNT));
String shortName =
cursor.getString(cursor.getColumnIndex(ExchangeRatesData.C_SHORT_NAME));
TextView textExchangeRate = (TextView) view;
textExchangeRate.setText(amount + " " + shortName + " = " + rate + " zł");
return true;
}
if (view.getId() == R.id.selectedBox)
{
CheckBox selectedBox = (CheckBox) view;
final String shortName =
cursor.getString(cursor.getColumnIndex(ExchangeRatesData.C_SHORT_NAME));
selectedBox.setChecked(cursor.getInt(cursor.getColumnIndex(ExchangeRatesData.C_SELECTED))
> 0);
return true;
}
return false;
}
};
}
********************************************************************************************************
Checkbox means something like add item to favourites. So I need to receive
CheckBox changing state event is some nice and neat way.
Please could you give me some tips, how should I do it?
Cheers,
Jacek
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en