sqlite를 조회하는 리스트뷰에 스피너를 넣어 드롭박스를 만들어 sqlite를 갱신하고 싶습니다.
package com.example.smslist;
import android.annotation.SuppressLint;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class UseLookupActivity extends AppCompatActivity {
Cursor cur;
ListView listView;
SmsDatabaseHelper payDB = new SmsDatabaseHelper(this);
int thisMonthSpend = 0;
Date currentTime = Calendar.getInstance().getTime();
String date_text = new SimpleDateFormat("yyyy-MM", Locale.getDefault()).format(currentTime);
SQLiteDatabase db;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_use_lookup);
final TextView usemoney = (TextView)findViewById(R.id.usemoney);
db = payDB.getWritableDatabase();
cur=db.rawQuery("Select sum(pay) from PAY_LIST where pay_date like'"+date_text+"%'", null);
while (cur.moveToNext()) {
if (cur.getString(0) != null) {
thisMonthSpend = cur.getInt(0);
break;
}
}
usemoney.setText(Integer.toString(thisMonthSpend)+" 원");
//sqlite 리스트뷰 조회------------------------------------------------------------------------------------------------------
listView = (ListView)findViewById(R.id.listView);
cur = db.rawQuery("Select pay_id as _id, * from PAY_LIST order by pay_id desc",null);
String[] from = new String[]{"pay_date","pay_card","pay","category"}; //category 부분을 스피너로 넣고싶습니다.
int[] to = new int[]{R.id.textView1,R.id.textView2,R.id.textView3,R.id.textView4};
cur.moveToFirst();
final SimpleCursorAdapter adapter = new SimpleCursorAdapter(listView.getContext(),R.layout.item,cur,from,to);
listView.setAdapter(adapter);
db.close();
}
//-----------------------------------------------------------------------------------------------------------------------
public void onResume(){
super.onResume();
db = payDB.getWritableDatabase();
cur=db.rawQuery("Select sum(pay) from PAY_LIST where pay_date like'"+date_text+"%'", null);
while (cur.moveToNext()) {
if (cur.getString(0) != null) {
thisMonthSpend = cur.getInt(0);
break;
}
}
final TextView usemoney = (TextView)findViewById(R.id.usemoney);
usemoney.setText(Integer.toString(thisMonthSpend)+" 원");
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="88dp"
android:layout_height="20dp"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="68dp"
android:layout_height="20dp"
android:paddingLeft="10dp"/>
<TextView
android:id="@+id/textView3"
android:layout_width="78dp"
android:layout_height="20dp"
android:paddingLeft="10dp"/>
<TextView
android:id="@+id/textView4"
android:layout_width="48dp"
android:layout_height="20dp"
android:paddingLeft="10dp"/>
</LinearLayout>
</RelativeLayout>