Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How can i get checkbox position into listview to remove corresponding textview

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
i have created listview where each row has one textview and checkbox. when checkbox is checked i want to remove corresponding textview i.e i want to remove like list.remove(position). Let, me know in depth. thanks.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You can control the visibility of the TextView using View#setVisibility(int visibility) depending on the check box selection
 
viral thakar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello sir, actually i want to remove from arraylist.remove (position) when corresponding to checkbox is clicked.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
You are not being clear on what you wish to achieve.

viral thakar wrote:I have created listview where each row has one textview and checkbox. when checkbox is checked i want to remove corresponding textview


So do you wish to remove the TextView or the whole row? Also, if the whole row is removed, you cannot bring it back by toggling the check box (because the check box too will be gone) Is this an acceptable scenario?

viral thakar wrote: i want to remove from arraylist.remove (position) when corresponding to checkbox is clicked.


What is this arraylist? Please TellTheDetails
 
viral thakar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hello sir, I have Arraylist into bean class@Line 1 Below. I have mainActivity class @ Line 2 Below where i set data to listview using myAdapter(CustomAdapter class). each row has one textview and checkbox. i want to do when checkbox is checked i want to obtain that checkbox position so i can remove corresponding textview so, i used below l1.remove(i) it' s work find but what happen i have to click on listview item to remove the item but want to remove iwhen checkbox is checked or clicked i want to remove corresponding item. thanks.


Line 1>>> public class Bean {




static ArrayList<String> getList(){

ArrayList<String> l1=new ArrayList<String>();

l1.add("Laptop");
l1.add("Desktop");
l1.add("Pendrive");

return l1;
}
}
//////////////////////////////////////////////



Line 2>> public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


final ArrayList<String> l1=Bean.getList();



final ListView l2=(ListView)findViewById(R.id.listView1);
Button b1=(Button)findViewById(R.id.button1);


final myAdapter1 adapter = new myAdapter1(this, l1);
l2.setAdapter(adapter);




b1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

SparseBooleanArray boolArray=l2.getCheckedItemPositions();

for(int i=0;i<l1.size();i++)
{
if(boolArray.valueAt(i)==true)
{
l1.remove(i);
}
}
adapter.notifyDataSetChanged();


}
});



}


}

3>> public class myAdapter1 extends BaseAdapter
{



ArrayList<String> listItem;

Activity activity;




public myAdapter1(Activity activity, ArrayList<String> l1) {
// TODO Auto-generated constructor stub
listItem=l1;
this.activity=activity;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return listItem.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}

public class ViewHolder
{
TextView txtViewItem;
CheckBox chk;
}

@Override
public View getView(final int position, View view, ViewGroup parent) {
// TODO Auto-generated method stub

final ViewHolder item;
LayoutInflater inflater = activity.getLayoutInflater();

if(view==null)
{
view = inflater.inflate(R.layout.activity_main, null);
item = new ViewHolder();

item.txtViewItem = (TextView) view.findViewById(R.id.textView1);
item.chk=(CheckBox)view.findViewById(R.id.checkBox1);
view.setTag(item);
}
else
{
item = (ViewHolder) view.getTag();
}

item.txtViewItem.setText(listItem.get(position));



return view;
}
}



[/img]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Closing this topic, as the discussion is being continued in another topic: https://coderanch.com/t/621310/Android/Mobile/checkbox-position-listview-remove-textview
 
    Bookmark Topic Watch Topic
  • New Topic