Friday, 6 September 2013

Editing data in a List View item

Editing data in a List View item

Can't seem to find a solution to this. I'm trying to edit the data in my
List View item. The List View uses an array adapter to display the data in
a row in the list view.
The user holds their finger over the list view item they wish to edit and
the data from that list view item is supposed to be transferred over to
the other activity where the user can edit it. Instead of transferring the
data that I want to edit, the data from the last item in the List View is
transferred.
This is the code below.
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
int position = info.position;
switch (item.getItemId()) {
case R.id.edit:
{
itemCheck = true;
String bCheck = String.valueOf(itemCheck);
iTitle = paymentTitle.get(position).toString();
iPaymentDate = paymentDate.get(position).toString();
iReminderDate = reminderDate.get(position).toString();
iReminderTime = reminderTime.get(position).toString();
iAmount = paymentVal.get(position).toString();
if(iReminderDate == "No Date Set")
{
iReminderDate = "";
}
else
{
Intent reminder = new Intent(this,
MyBroadcastReceiver.class);
PendingIntent.getBroadcast(this.getApplicationContext(),
1, reminder,
PendingIntent.FLAG_UPDATE_CURRENT).cancel();
}
if(iReminderTime == "No Time Set")
{
iReminderTime = "";
}
Intent intent = new Intent(Payments.this, AddPayment.class);
intent.putExtra("PID", pID);
intent.putExtra("ITITLE", pTitle);
intent.putExtra("PAYMENTDAY", pDay);
intent.putExtra("PAYMENTMONTH", pMonth);
intent.putExtra("PAYMENTYEAR", pYear);
intent.putExtra("REMINDERDAY", rDay);
intent.putExtra("REMINDERMONTH", rMonth);
intent.putExtra("REMINDERYEAR", rYear);
intent.putExtra("REMINDERHOUR", rHour);
intent.putExtra("REMINDERMIN", rMin);
intent.putExtra("IAMOUNT", pValue);
intent.putExtra("ITEMCHECK", itemCheck);
startActivity(intent);
finish();
}
return true;
This is the data from my database
C = readableDB.query("PaymentTable", new String[] { "_ID", "PTITLE", "PA",
"PDAY", "PMONTH", "PYEAR", "RDAY", "RMONTH",
"RYEAR", "RMIN", "RHOUR", "DATE"}, null, null, null, null,
"DATE ASC");
This is how the variables is created using the data imported from the
Database.
paymentID = C.getInt(C.getColumnIndex("_ID"));
pTitle = C.getString(C.getColumnIndex("PTITLE"));
pDay = C.getString(C.getColumnIndex("PDAY"));
pMonth = C.getString(C.getColumnIndex("PMONTH"));
pYear = C.getString(C.getColumnIndex("PYEAR"));
rDay = C.getString(C.getColumnIndex("RDAY"));
rMonth = C.getString(C.getColumnIndex("RMONTH"));
rYear = C.getString(C.getColumnIndex("RYEAR"));
rHour = C.getString(C.getColumnIndex("RHOUR"));
rMin = C.getString(C.getColumnIndex("RMIN"));
pValue = C.getString(C.getColumnIndex("PA"));
pID = paymentID.toString();
This is how the array list items are made which are used to display the
data in my list view.
reminderDateStr = rDay + "/" + rMonth + "/" + rYear;
reminderTimeStr = rHour + ":" + rMin;
paymentDateStr = pDay + "/" + pMonth + "/" + pYear;
paymentTitleStr = pTitle;
paymentValue = "£" + pValue;
paymentTitle.add(paymentTitleStr);
reminderTime.add(reminderTimeStr);
paymentDate.add(paymentDateStr);
reminderDate.add(reminderDateStr);
paymentVal.add(paymentValue);

No comments:

Post a Comment