• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Can data be captured from a string buffer?

I've been working on my first Android app. I wanted a slicker way to delete an entry from an sqlite database than having the user type in the entry they want to delete. Currently all the information is displayed in a stringbuffer. Is this even possible or would I need some other way to display the data and capture the tap or click.
Thanks so much!


Java:
 public void DeleteOilChange()
    {
        DeleteOilChangeButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                Integer deletedRows= CMDB.DeleteCar(Editoildate.getText().toString());
                if(deletedRows>0)
                {
                    Toast.makeText(getActivity(),"Oil Change Deleted", Toast.LENGTH_LONG).show();

                }
                else
                {
                    Toast.makeText(getActivity(),"Oil Change Not Deleted", Toast.LENGTH_LONG).show();

                }
            }
        });
    }


Java:
public void ViewOilChanges()
    {
        ViewOilChangesButton.setOnClickListener(new View.OnClickListener()
         {
           @Override
           public void onClick(View view)
           {
             Cursor result=CMDB.GetOilChanges();
              if(result.getCount()==0)
              {
               ShowMessage("Error", "Nothing Found!");
               return;
              }
             StringBuffer buffer= new StringBuffer();
              while(result.moveToNext())
               {
                 buffer.append("Date of Service:" +result.getString(0)+ "\n");
                 buffer.append("Place of Service:" +result.getString(1)+ "\n");
                 buffer.append("Labor:" +result.getString(2)+ "\n");
                 buffer.append("Mileage:" +result.getString(3)+ "\n");
                 buffer.append("Oil Brand:" +result.getString(4)+ "\n");
                 buffer.append("Oil Price:" +result.getString(5)+ "\n");
                 buffer.append("Filter Brand:" +result.getString(6)+ "\n");
                 buffer.append("Filter Price:" +result.getString(7)+ "\n");
                 buffer.append("Purchase Place:" +result.getString(8)+ "\n\n");
               }

            //Show Data
           ShowMessage("Success", buffer.toString());
         }
                                                }
        );
    }
 
It really depends how you present the information to the user. If you used a ListView, and provided a means of selecting one or more items in the list, you could put a delete icon in the toolbar, which would perform the delete.
 
Do you mean "a slicker way" is using a "swipe gesture" to delete record?
If yes, this is an interesting way.
You need to show your records of database in RecyclerView instead of StringBuffer.
Then attach ItemTouchHelper to RecyclerView to remove records from RecyclerView and database.
This is demo project https://github.com/udacity/ToDoList_final
 
Last edited:
It really depends how you present the information to the user. If you used a ListView, and provided a means of selecting one or more items in the list, you could put a delete icon in the toolbar, which would perform the delete.
This is likely what I will use. I just ran across a tutorial that explained just that.
 
This is likely what I will use. I just ran across a tutorial that explained just that.

Thanks, but the suggestion of RecyclerView is better. This gives you built-in View recycling, which is what you'll have to do with the ListView anyway.
 
Back
Top Bottom