我想與您覈對, 我想爲我的申請做一個總結。 這樣它會給我一個平均的價格基於月份。如何獲取指定月份的數據並將其除以天數
這意味着我有一組記錄,我已經按月過濾了這些記錄。 如果month = Jan,我希望得到所有Jan數據併除以當月的天數。 現在, 我只能拿出幾個月。 我想檢查, 如果我想這樣做「想獲得所有Jan數據併除以本月的天數」,我該怎麼辦? 任何人都可以向我建議嗎?
即時通訊新的android,並試圖學習的東西。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.summary);
monthDate = (EditText)findViewById(R.id.month);
avgPrice = (TextView)findViewById(R.id.showavfPriceTV);
exFuel = (TextView)findViewById(R.id.showexFuelTV);
avgFC = (TextView)findViewById(R.id.showavgFCTV);
doneButton = (Button)findViewById(R.id.doneBTN);
exitButton = (Button)findViewById(R.id.exitBTN);
// First we need to make contact with the database we have created using
// the DbHelper class
AndroidOpenDbHelper openHelperClass = new AndroidOpenDbHelper(this);
// Then we need to get a readable database
SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();
// We need a a guy to read the database query. Cursor interface will do
// it for us
// (String table, String[] columns, String selection, String[]
// selectionArgs, String groupBy, String having, String orderBy)
Cursor cursor = sqliteDatabase.query(
AndroidOpenDbHelper.TABLE_NAME_LOG, null, null, null, null,
null, null);
// Above given query, read all the columns and fields of the table
startManagingCursor(cursor);
// Cursor object read all the fields. So we make sure to check it will
// not miss any by looping through a while loop
while (cursor.moveToNext()) {
// In one loop, cursor read one undergraduate all details
// Assume, we also need to see all the details of each and every
// undergraduate
// What we have to do is in each loop, read all the values, pass
// them to the POJO class
// and create a ArrayList of undergraduates
String id = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_ROWID));
final String date = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_DATE));
String price = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_PRICE));
String pump = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_FUEL));
String cost = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_COST));
String odm = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_ODM));
String preodm = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_PREODM));
String fcon = cursor.getString(cursor
.getColumnIndex(AndroidOpenDbHelper.KEY_CON));
// If you don't close the database, you will get an error
sqliteDatabase.close();
Log.i("FuelLog", "dataBundle " + date);
monthDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// showDialog(DATE_DIALOG_ID);
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
});
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (monthDate.getText().toString().equals(date.subSequence(3,9).toString()))
{
Log.d("MONTHDATE","date : "+ monthDate.getText().toString());
Log.d("BBUNDLEDATE","date : "+ (date.subSequence(3,9).toString()));
Intent intent=new Intent(getApplicationContext(),homeActivity.class);
startActivity(intent);
}
else
{
Intent intent=new Intent(getApplicationContext(),about.class);
startActivity(intent);
Log.d("ELSEMONTHDATE","date : "+ monthDate.getText().toString());
Log.d("ELSEBUNDLEDATE","date : "+ (date.subSequence(3,9).toString()));
}
}
});
}
}
我不明白個好主意, 你能進一步解釋? – Chloe
我只是混淆瞭如何獲取數據。 例如, 我有一組記錄,2條記錄是1月,3條記錄是2月 如果我點擊摘要(feb), 我想將FEB月份的PRICE記錄加在一起,然後除以天數。 我該怎麼做? – Chloe
如何添加PRICE? – Chloe