rwe
rwe

Reputation: 119

how to set delete buttons in each item of a list view in android?

I have list view. I need to set delete button to each row. Is there any standard way to do this in android?

Thank you very much.

Upvotes: 0

Views: 637

Answers (3)

robocoder
robocoder

Reputation: 113

You have to do xml file with single row (with button) then make class which extends some Adapter for example:

arrayAdapter = new MyArrayAdapter(this, R.layout.news_row, newsList) where MyArrayAdapter extends ArrayAdapter, news_row is xml with view of single row, newsList is ArrayList with data

Upvotes: 0

Martyn
Martyn

Reputation: 16622

You need to write your own list view item layout, which includes a delete button, see here for some details on that. In the button XMl you need to have the android:onclick attribute set, then in your code have an appropiate matching method. for example

<button android:onclick="deleteItem" android:text="Delete" ...>

public void deleteItem(View view) {
    ... code to delete...
}

Upvotes: 0

PravinCG
PravinCG

Reputation: 7708

Android way is to not have a delete button but an action based on long press. So when you long press on the list it will show a list of stuff you can do and include delete in it. For example, you can check your Gmail, sms and long press on the thread to get this option.

Upvotes: 2

Related Questions