データベースからlistView
によって埋められる があります。すべてのエントリには 、値、時間、日付の 3 つがあります。simpleCursorAdapter
sqlite
listView
textViews
listView cursor
日付の値でフィルター処理するので、フィルターに入力すると24-07-2013
、日付が設定されている sqlite データベースからのエントリのみが表示されます。エントリの数に応じて、1 または 3 または任意の数値が表示されることがあります。データベース。
私がやりたいのは、すべてValues
を合計に追加し、それを個別に表示するTextView
ことです。
だから私の質問は次のとおりです。Values
から を取得して合計するにはどうすればよいlistView
ですか
これが私のコードです。すべてをコピーしないようにします。
private void displayListView() {
Cursor cursor = dbHelper.fetchAllCountries();
// The desired columns to be bound
String[] columns = new String[] {
SQLiteT.DB_COLUMN_1_NAME3,
SQLiteT.DB_COLUMN_2_NAME3,
SQLiteT.DB_COLUMN_3_NAME3,
};
int[] to = new int[] {
R.id.numeprod3,
R.id.cantotala3,
R.id.ultimulpret3,
};
dataAdapter = new SimpleCursorAdapter(this, R.layout.country_info3,
cursor, columns, to, 0);
ListView listView = (ListView) findViewById(R.id.listView13);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
myFilter = (EditText) findViewById(R.id.myFilter3);
myFilter.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
dataAdapter.getFilter().filter(s.toString());
}
});
dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return dbHelper.fetchCountriesByName(constraint.toString());
そして、これはデータベースからデータを抽出する方法です:
public Cursor fetchCountriesByName(String inputText) throws SQLException {
Cursor mCursor = null;
if (inputText == null || inputText.length() == 0) {
mCursor = this.sqliteDBInstance3.query(DB_TABLE_NAME3, new String[] {KEY_ROWID,
DB_COLUMN_1_NAME3, DB_COLUMN_2_NAME3, DB_COLUMN_3_NAME3
}, null, null, null, null, null);
} else {
mCursor = this.sqliteDBInstance3.query(true, DB_TABLE_NAME3,
new String[] {KEY_ROWID, DB_COLUMN_1_NAME3,
DB_COLUMN_2_NAME3, DB_COLUMN_3_NAME3 },
DB_COLUMN_3_NAME3 + " like '%" + inputText + "%'", null,
null, null, null, null);
}
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public Cursor fetchAllCountries() {
Cursor mCursor = this.sqliteDBInstance3.query(DB_TABLE_NAME3,
new String[] {KEY_ROWID, DB_COLUMN_1_NAME3, DB_COLUMN_2_NAME3,
DB_COLUMN_3_NAME3 }, null, null, null, null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
アップデート :
私はこれをやってしまいました.それは私が思う最も良い解決策ではありませんが、それは仕事をします.
//Added to this :
public void onTextChanged(CharSequence s, int start, int before,
int count) {
dataAdapter.getFilter().filter(s.toString());
totaluri= dbHelper.getAllCountries(s.toString());
//ore=dbHelper.getAllCountries2(s.toString());
int pff=totaluri.length;
float totalulma = 0;
for(int i=0;i<pff;i++){totalulma=totalulma+Float.parseFloat(totaluri[i]);}
totaltotaluri.setText(String.format("Total: %.2f", totalulma));
//And created this method inside my database activity
public String[] getAllCountries(String inputText) {
Cursor cursor = this.sqliteDBInstance3.query(DB_TABLE_NAME3,
new String[] { DB_COLUMN_1_NAME3 }, DB_COLUMN_3_NAME3 + " like '%" + inputText + "%'", null, null, null,
null);
if (cursor.getCount() > 0) {
String[] str = new String[cursor.getCount()];
int i = 0;
while (cursor.moveToNext()) {
str[i] = cursor.getString(cursor
.getColumnIndex(DB_COLUMN_1_NAME3));
i++;
}
return str;
} else {
return new String[] {};
}
}
そのため、フィルター edittext の入力が変更されると、データベースで別のクエリが実行されます。これを行うためのより良い、より効率的な方法があれば教えてください...私は本当に学びたいのですが、もちろん、知りません。アプリで大量のリソースを使用させたい。