Remove items from ListView with a custom adapter
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a custom ListView
and adapter. I can delete an item from my lists which are set on my custom list, but I can delete from ListView
. When I try to call adapter.remove(position)
the editor is saying to "create a method "remove(int position)""
. I don't know what should I do when I create this method into the adapter. Code :
Filling my listview:
lv = (ListView) findViewById(R.id.list);
LayoutInflater mLInflater = getLayoutInflater();
final ListViewAdapter adapter = new ListViewAdapter(
getApplicationContext(), kimdenlist, konulist,
mLInflater);
lv.setAdapter(adapter);
ListViewAdapter:
public class ListViewAdapter extends BaseAdapter {
static HashMap<Integer, Boolean> cartItems = new HashMap<Integer, Boolean>();
Context mContext;
ArrayList<String> kimdenlist; // to load images
ArrayList<String> konulist; // for data
LayoutInflater mLayoutInflater;
public ListViewAdapter(Context context, ArrayList<String> kimdenlist, ArrayList<String> konulist,
LayoutInflater layoutInflater) {
mContext = context;
this.kimdenlist = kimdenlist;
this.konulist = konulist;
mLayoutInflater = layoutInflater;
}
@Override
public int getCount()
{
return kimdenlist.size(); // images array length
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
int count = 0;
// customized Listview
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
View v;
final int pos = position;
v = mLayoutInflater.inflate(R.layout.listust, null);
TextView kimden = (TextView) v.findViewById(R.id.textvKimden);
kimden.setText(kimdenlist.get(position));
TextView konu = (TextView) v.findViewById(R.id.textvKonu);
konu.setText(konulist.get(position));
CheckBox ch = (CheckBox) v.findViewById(R.id.chk);
try {
if (count != 0) {
boolean b = cartItems.get(pos);
if (b == false)
ch.setChecked(false);
else
ch.setChecked(true);
}
} catch (NullPointerException e) {
}
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
cartItems.put(pos, arg1);
count++;
}
});
return v;
}
public static HashMap<Integer, Boolean> getcartItems() {
return cartItems;
}
}
When I click to "delete_Button" : I can only remove from lists:
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
android android-listview customization adapter
add a comment |
I have a custom ListView
and adapter. I can delete an item from my lists which are set on my custom list, but I can delete from ListView
. When I try to call adapter.remove(position)
the editor is saying to "create a method "remove(int position)""
. I don't know what should I do when I create this method into the adapter. Code :
Filling my listview:
lv = (ListView) findViewById(R.id.list);
LayoutInflater mLInflater = getLayoutInflater();
final ListViewAdapter adapter = new ListViewAdapter(
getApplicationContext(), kimdenlist, konulist,
mLInflater);
lv.setAdapter(adapter);
ListViewAdapter:
public class ListViewAdapter extends BaseAdapter {
static HashMap<Integer, Boolean> cartItems = new HashMap<Integer, Boolean>();
Context mContext;
ArrayList<String> kimdenlist; // to load images
ArrayList<String> konulist; // for data
LayoutInflater mLayoutInflater;
public ListViewAdapter(Context context, ArrayList<String> kimdenlist, ArrayList<String> konulist,
LayoutInflater layoutInflater) {
mContext = context;
this.kimdenlist = kimdenlist;
this.konulist = konulist;
mLayoutInflater = layoutInflater;
}
@Override
public int getCount()
{
return kimdenlist.size(); // images array length
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
int count = 0;
// customized Listview
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
View v;
final int pos = position;
v = mLayoutInflater.inflate(R.layout.listust, null);
TextView kimden = (TextView) v.findViewById(R.id.textvKimden);
kimden.setText(kimdenlist.get(position));
TextView konu = (TextView) v.findViewById(R.id.textvKonu);
konu.setText(konulist.get(position));
CheckBox ch = (CheckBox) v.findViewById(R.id.chk);
try {
if (count != 0) {
boolean b = cartItems.get(pos);
if (b == false)
ch.setChecked(false);
else
ch.setChecked(true);
}
} catch (NullPointerException e) {
}
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
cartItems.put(pos, arg1);
count++;
}
});
return v;
}
public static HashMap<Integer, Boolean> getcartItems() {
return cartItems;
}
}
When I click to "delete_Button" : I can only remove from lists:
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
android android-listview customization adapter
add a comment |
I have a custom ListView
and adapter. I can delete an item from my lists which are set on my custom list, but I can delete from ListView
. When I try to call adapter.remove(position)
the editor is saying to "create a method "remove(int position)""
. I don't know what should I do when I create this method into the adapter. Code :
Filling my listview:
lv = (ListView) findViewById(R.id.list);
LayoutInflater mLInflater = getLayoutInflater();
final ListViewAdapter adapter = new ListViewAdapter(
getApplicationContext(), kimdenlist, konulist,
mLInflater);
lv.setAdapter(adapter);
ListViewAdapter:
public class ListViewAdapter extends BaseAdapter {
static HashMap<Integer, Boolean> cartItems = new HashMap<Integer, Boolean>();
Context mContext;
ArrayList<String> kimdenlist; // to load images
ArrayList<String> konulist; // for data
LayoutInflater mLayoutInflater;
public ListViewAdapter(Context context, ArrayList<String> kimdenlist, ArrayList<String> konulist,
LayoutInflater layoutInflater) {
mContext = context;
this.kimdenlist = kimdenlist;
this.konulist = konulist;
mLayoutInflater = layoutInflater;
}
@Override
public int getCount()
{
return kimdenlist.size(); // images array length
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
int count = 0;
// customized Listview
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
View v;
final int pos = position;
v = mLayoutInflater.inflate(R.layout.listust, null);
TextView kimden = (TextView) v.findViewById(R.id.textvKimden);
kimden.setText(kimdenlist.get(position));
TextView konu = (TextView) v.findViewById(R.id.textvKonu);
konu.setText(konulist.get(position));
CheckBox ch = (CheckBox) v.findViewById(R.id.chk);
try {
if (count != 0) {
boolean b = cartItems.get(pos);
if (b == false)
ch.setChecked(false);
else
ch.setChecked(true);
}
} catch (NullPointerException e) {
}
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
cartItems.put(pos, arg1);
count++;
}
});
return v;
}
public static HashMap<Integer, Boolean> getcartItems() {
return cartItems;
}
}
When I click to "delete_Button" : I can only remove from lists:
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
android android-listview customization adapter
I have a custom ListView
and adapter. I can delete an item from my lists which are set on my custom list, but I can delete from ListView
. When I try to call adapter.remove(position)
the editor is saying to "create a method "remove(int position)""
. I don't know what should I do when I create this method into the adapter. Code :
Filling my listview:
lv = (ListView) findViewById(R.id.list);
LayoutInflater mLInflater = getLayoutInflater();
final ListViewAdapter adapter = new ListViewAdapter(
getApplicationContext(), kimdenlist, konulist,
mLInflater);
lv.setAdapter(adapter);
ListViewAdapter:
public class ListViewAdapter extends BaseAdapter {
static HashMap<Integer, Boolean> cartItems = new HashMap<Integer, Boolean>();
Context mContext;
ArrayList<String> kimdenlist; // to load images
ArrayList<String> konulist; // for data
LayoutInflater mLayoutInflater;
public ListViewAdapter(Context context, ArrayList<String> kimdenlist, ArrayList<String> konulist,
LayoutInflater layoutInflater) {
mContext = context;
this.kimdenlist = kimdenlist;
this.konulist = konulist;
mLayoutInflater = layoutInflater;
}
@Override
public int getCount()
{
return kimdenlist.size(); // images array length
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
int count = 0;
// customized Listview
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
View v;
final int pos = position;
v = mLayoutInflater.inflate(R.layout.listust, null);
TextView kimden = (TextView) v.findViewById(R.id.textvKimden);
kimden.setText(kimdenlist.get(position));
TextView konu = (TextView) v.findViewById(R.id.textvKonu);
konu.setText(konulist.get(position));
CheckBox ch = (CheckBox) v.findViewById(R.id.chk);
try {
if (count != 0) {
boolean b = cartItems.get(pos);
if (b == false)
ch.setChecked(false);
else
ch.setChecked(true);
}
} catch (NullPointerException e) {
}
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
cartItems.put(pos, arg1);
count++;
}
});
return v;
}
public static HashMap<Integer, Boolean> getcartItems() {
return cartItems;
}
}
When I click to "delete_Button" : I can only remove from lists:
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
android android-listview customization adapter
android android-listview customization adapter
edited May 10 '12 at 18:55
Luksprog
81.1k16175178
81.1k16175178
asked May 10 '12 at 18:21
MerveMerve
71461936
71461936
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
It's because your listViewAdapter has not remove method! You extend BaseAdapter and it has not remove method. You shoud create remove method in listviewAdapter and it will looks like
public void remove(int position){
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
}
You have to understand how list view and adapter works. Adapter holds data for listview. Adapter method getView is called when list line is going to be created. List size is calculated by value returned by adapter's getCount() and so on...
I am already doing this. My list's item are deleted but my listview's item is not delete. For instance; I click the position=0 and position zero has "A11" for konulist, "A1" for kimdenlist. And position=1 has "B11" for konulist, "B1" for kimdenlist. And they listed on listview . When I delete the position=0 and then get back to the listview--> position=0 still there! BUT (as I continue to process) I click the position=0 it is show me position=1's data.
– Merve
May 10 '12 at 18:52
1
@Merve CallnotifyDataSetChanged()
after you delete an item.
– Luksprog
May 10 '12 at 18:53
2
It didnt change the situation
– Merve
May 10 '12 at 19:02
add a comment |
To remove an item from ListView BUT NOT INSIDE ADAPTER CLASS:
lv.removeViewAt(index);
adapter.notifyDataSetChanged();
where "index" specifies the position or index in the ListView that holds the item to delete.
To remove an item from ListView INSIDE ADAPTER CLASS: First you need to add a Tag to each item in the list. use some layout within the content item in the list to assign that Tag. This can be done within the method getView ().
@Override
public View getView(int position, View convertView, ViewGroup parent) {
row = convertView;
if(row == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.item_lista_lugares_visitar, parent, false);
holder = new ViewHolder();
// ... DO WHAT YOU NEED HERE
holder.linearLayoutContainer = (LinearLayout) row.findViewById(R.id.ll_container);
// Set the position as a Tag for the view
holder.linearLayoutContainer.setTag(position);
} else {
holder = (ViewHolder) row.getTag();
}
// ... DO WHAT YOU NEED HERE
return row;
}
// Method for remove an item of ListView inside adapter class
// you need to pass as an argument the tag you added to the layout of your choice
public void removeView(Object position) {
// lv and the adapter must be public-static in their Activity Class
SomeActivity.lv.removeViewAt(Integer.parteInt(position).toString());
SomeActivity.adapter.notifyDataSetChanged();
}
add a comment |
After your code
konulist.remove(konulist.get(position));
kimdenlist.remove(kimdenlist.get(position));
you can call the method:
notifyDataSetChanged();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10539996%2fremove-items-from-listview-with-a-custom-adapter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's because your listViewAdapter has not remove method! You extend BaseAdapter and it has not remove method. You shoud create remove method in listviewAdapter and it will looks like
public void remove(int position){
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
}
You have to understand how list view and adapter works. Adapter holds data for listview. Adapter method getView is called when list line is going to be created. List size is calculated by value returned by adapter's getCount() and so on...
I am already doing this. My list's item are deleted but my listview's item is not delete. For instance; I click the position=0 and position zero has "A11" for konulist, "A1" for kimdenlist. And position=1 has "B11" for konulist, "B1" for kimdenlist. And they listed on listview . When I delete the position=0 and then get back to the listview--> position=0 still there! BUT (as I continue to process) I click the position=0 it is show me position=1's data.
– Merve
May 10 '12 at 18:52
1
@Merve CallnotifyDataSetChanged()
after you delete an item.
– Luksprog
May 10 '12 at 18:53
2
It didnt change the situation
– Merve
May 10 '12 at 19:02
add a comment |
It's because your listViewAdapter has not remove method! You extend BaseAdapter and it has not remove method. You shoud create remove method in listviewAdapter and it will looks like
public void remove(int position){
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
}
You have to understand how list view and adapter works. Adapter holds data for listview. Adapter method getView is called when list line is going to be created. List size is calculated by value returned by adapter's getCount() and so on...
I am already doing this. My list's item are deleted but my listview's item is not delete. For instance; I click the position=0 and position zero has "A11" for konulist, "A1" for kimdenlist. And position=1 has "B11" for konulist, "B1" for kimdenlist. And they listed on listview . When I delete the position=0 and then get back to the listview--> position=0 still there! BUT (as I continue to process) I click the position=0 it is show me position=1's data.
– Merve
May 10 '12 at 18:52
1
@Merve CallnotifyDataSetChanged()
after you delete an item.
– Luksprog
May 10 '12 at 18:53
2
It didnt change the situation
– Merve
May 10 '12 at 19:02
add a comment |
It's because your listViewAdapter has not remove method! You extend BaseAdapter and it has not remove method. You shoud create remove method in listviewAdapter and it will looks like
public void remove(int position){
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
}
You have to understand how list view and adapter works. Adapter holds data for listview. Adapter method getView is called when list line is going to be created. List size is calculated by value returned by adapter's getCount() and so on...
It's because your listViewAdapter has not remove method! You extend BaseAdapter and it has not remove method. You shoud create remove method in listviewAdapter and it will looks like
public void remove(int position){
konulist.remove(konulist.get(position));;
kimdenlist.remove(kimdenlist.get(position));
}
You have to understand how list view and adapter works. Adapter holds data for listview. Adapter method getView is called when list line is going to be created. List size is calculated by value returned by adapter's getCount() and so on...
answered May 10 '12 at 18:46
vandzivandzi
1,70712047
1,70712047
I am already doing this. My list's item are deleted but my listview's item is not delete. For instance; I click the position=0 and position zero has "A11" for konulist, "A1" for kimdenlist. And position=1 has "B11" for konulist, "B1" for kimdenlist. And they listed on listview . When I delete the position=0 and then get back to the listview--> position=0 still there! BUT (as I continue to process) I click the position=0 it is show me position=1's data.
– Merve
May 10 '12 at 18:52
1
@Merve CallnotifyDataSetChanged()
after you delete an item.
– Luksprog
May 10 '12 at 18:53
2
It didnt change the situation
– Merve
May 10 '12 at 19:02
add a comment |
I am already doing this. My list's item are deleted but my listview's item is not delete. For instance; I click the position=0 and position zero has "A11" for konulist, "A1" for kimdenlist. And position=1 has "B11" for konulist, "B1" for kimdenlist. And they listed on listview . When I delete the position=0 and then get back to the listview--> position=0 still there! BUT (as I continue to process) I click the position=0 it is show me position=1's data.
– Merve
May 10 '12 at 18:52
1
@Merve CallnotifyDataSetChanged()
after you delete an item.
– Luksprog
May 10 '12 at 18:53
2
It didnt change the situation
– Merve
May 10 '12 at 19:02
I am already doing this. My list's item are deleted but my listview's item is not delete. For instance; I click the position=0 and position zero has "A11" for konulist, "A1" for kimdenlist. And position=1 has "B11" for konulist, "B1" for kimdenlist. And they listed on listview . When I delete the position=0 and then get back to the listview--> position=0 still there! BUT (as I continue to process) I click the position=0 it is show me position=1's data.
– Merve
May 10 '12 at 18:52
I am already doing this. My list's item are deleted but my listview's item is not delete. For instance; I click the position=0 and position zero has "A11" for konulist, "A1" for kimdenlist. And position=1 has "B11" for konulist, "B1" for kimdenlist. And they listed on listview . When I delete the position=0 and then get back to the listview--> position=0 still there! BUT (as I continue to process) I click the position=0 it is show me position=1's data.
– Merve
May 10 '12 at 18:52
1
1
@Merve Call
notifyDataSetChanged()
after you delete an item.– Luksprog
May 10 '12 at 18:53
@Merve Call
notifyDataSetChanged()
after you delete an item.– Luksprog
May 10 '12 at 18:53
2
2
It didnt change the situation
– Merve
May 10 '12 at 19:02
It didnt change the situation
– Merve
May 10 '12 at 19:02
add a comment |
To remove an item from ListView BUT NOT INSIDE ADAPTER CLASS:
lv.removeViewAt(index);
adapter.notifyDataSetChanged();
where "index" specifies the position or index in the ListView that holds the item to delete.
To remove an item from ListView INSIDE ADAPTER CLASS: First you need to add a Tag to each item in the list. use some layout within the content item in the list to assign that Tag. This can be done within the method getView ().
@Override
public View getView(int position, View convertView, ViewGroup parent) {
row = convertView;
if(row == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.item_lista_lugares_visitar, parent, false);
holder = new ViewHolder();
// ... DO WHAT YOU NEED HERE
holder.linearLayoutContainer = (LinearLayout) row.findViewById(R.id.ll_container);
// Set the position as a Tag for the view
holder.linearLayoutContainer.setTag(position);
} else {
holder = (ViewHolder) row.getTag();
}
// ... DO WHAT YOU NEED HERE
return row;
}
// Method for remove an item of ListView inside adapter class
// you need to pass as an argument the tag you added to the layout of your choice
public void removeView(Object position) {
// lv and the adapter must be public-static in their Activity Class
SomeActivity.lv.removeViewAt(Integer.parteInt(position).toString());
SomeActivity.adapter.notifyDataSetChanged();
}
add a comment |
To remove an item from ListView BUT NOT INSIDE ADAPTER CLASS:
lv.removeViewAt(index);
adapter.notifyDataSetChanged();
where "index" specifies the position or index in the ListView that holds the item to delete.
To remove an item from ListView INSIDE ADAPTER CLASS: First you need to add a Tag to each item in the list. use some layout within the content item in the list to assign that Tag. This can be done within the method getView ().
@Override
public View getView(int position, View convertView, ViewGroup parent) {
row = convertView;
if(row == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.item_lista_lugares_visitar, parent, false);
holder = new ViewHolder();
// ... DO WHAT YOU NEED HERE
holder.linearLayoutContainer = (LinearLayout) row.findViewById(R.id.ll_container);
// Set the position as a Tag for the view
holder.linearLayoutContainer.setTag(position);
} else {
holder = (ViewHolder) row.getTag();
}
// ... DO WHAT YOU NEED HERE
return row;
}
// Method for remove an item of ListView inside adapter class
// you need to pass as an argument the tag you added to the layout of your choice
public void removeView(Object position) {
// lv and the adapter must be public-static in their Activity Class
SomeActivity.lv.removeViewAt(Integer.parteInt(position).toString());
SomeActivity.adapter.notifyDataSetChanged();
}
add a comment |
To remove an item from ListView BUT NOT INSIDE ADAPTER CLASS:
lv.removeViewAt(index);
adapter.notifyDataSetChanged();
where "index" specifies the position or index in the ListView that holds the item to delete.
To remove an item from ListView INSIDE ADAPTER CLASS: First you need to add a Tag to each item in the list. use some layout within the content item in the list to assign that Tag. This can be done within the method getView ().
@Override
public View getView(int position, View convertView, ViewGroup parent) {
row = convertView;
if(row == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.item_lista_lugares_visitar, parent, false);
holder = new ViewHolder();
// ... DO WHAT YOU NEED HERE
holder.linearLayoutContainer = (LinearLayout) row.findViewById(R.id.ll_container);
// Set the position as a Tag for the view
holder.linearLayoutContainer.setTag(position);
} else {
holder = (ViewHolder) row.getTag();
}
// ... DO WHAT YOU NEED HERE
return row;
}
// Method for remove an item of ListView inside adapter class
// you need to pass as an argument the tag you added to the layout of your choice
public void removeView(Object position) {
// lv and the adapter must be public-static in their Activity Class
SomeActivity.lv.removeViewAt(Integer.parteInt(position).toString());
SomeActivity.adapter.notifyDataSetChanged();
}
To remove an item from ListView BUT NOT INSIDE ADAPTER CLASS:
lv.removeViewAt(index);
adapter.notifyDataSetChanged();
where "index" specifies the position or index in the ListView that holds the item to delete.
To remove an item from ListView INSIDE ADAPTER CLASS: First you need to add a Tag to each item in the list. use some layout within the content item in the list to assign that Tag. This can be done within the method getView ().
@Override
public View getView(int position, View convertView, ViewGroup parent) {
row = convertView;
if(row == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.item_lista_lugares_visitar, parent, false);
holder = new ViewHolder();
// ... DO WHAT YOU NEED HERE
holder.linearLayoutContainer = (LinearLayout) row.findViewById(R.id.ll_container);
// Set the position as a Tag for the view
holder.linearLayoutContainer.setTag(position);
} else {
holder = (ViewHolder) row.getTag();
}
// ... DO WHAT YOU NEED HERE
return row;
}
// Method for remove an item of ListView inside adapter class
// you need to pass as an argument the tag you added to the layout of your choice
public void removeView(Object position) {
// lv and the adapter must be public-static in their Activity Class
SomeActivity.lv.removeViewAt(Integer.parteInt(position).toString());
SomeActivity.adapter.notifyDataSetChanged();
}
answered Apr 13 '15 at 4:38
flagg327flagg327
504518
504518
add a comment |
add a comment |
After your code
konulist.remove(konulist.get(position));
kimdenlist.remove(kimdenlist.get(position));
you can call the method:
notifyDataSetChanged();
add a comment |
After your code
konulist.remove(konulist.get(position));
kimdenlist.remove(kimdenlist.get(position));
you can call the method:
notifyDataSetChanged();
add a comment |
After your code
konulist.remove(konulist.get(position));
kimdenlist.remove(kimdenlist.get(position));
you can call the method:
notifyDataSetChanged();
After your code
konulist.remove(konulist.get(position));
kimdenlist.remove(kimdenlist.get(position));
you can call the method:
notifyDataSetChanged();
answered Nov 23 '18 at 1:48
Felipe OliveiraFelipe Oliveira
262
262
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10539996%2fremove-items-from-listview-with-a-custom-adapter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown