I want item from ListView disappear when I touch it. It is working but
problem is when I scroll list. Random items are disappearing or showing.
This is my code:
private ListView list;
(...)
list = (ListView) findViewById(R.id.units_list);
adapter = new UnitAdapter(this, R.layout.row_list, units);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
v.setVisibility(View.INVISIBLE);
}
});
ListView XML:
<ListView
android:id="#+id/units_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/strut"
android:layout_marginTop="5dp" >
</ListView>
row_list.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}"
android:descendantFocusability="blocksDescendants" >
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:gravity="center_vertical" />
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/img"
android:gravity="center_vertical"
android:textSize="14sp" />
<ImageView
android:id="#+id/upgrade"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:gravity="center_vertical" />
I tried too:
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
list.getChildAt(position).setVisibility(View.INVISIBLE);
}
And even:
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
list.getChildAt((int) id).setVisibility(View.INVISIBLE);
}
But it works same.
What is the problem? Why View is related with multiple rows? How can I fix this?
It may be related to the fact that a view in a ListView is recycled in Android, so when you edit a row you may see the difference when you scroll in multiple rows.
One solution could be to update the underlying adapter and then call notifyDataSetChanged. But there may be smoother solutions.
Use View Holder design pattern.
when you are removing the item from List View, remove the same from list(in your case unit) also.
Related
I have a listview in a constraintlayout.
when I try to do a long click on one of the elements of the list, to inflate the context menu, there are 2 problems:
1: It triggers the long click only sometimes, really random
2: After the long click was triggered the "normal" click is also triggered even though the onContextItemSelected returns true (to indicate the event was handled)
for some list elements, I want to have both the onClickListener and the long click for the contextmenu, on others only the contextmenu. (the listview is registered for contextmenu).
Heres the XML of the MainActivity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="it.netknights.piauthenticator.MainActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:backgroundTint="#color/PIBLUE"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#drawable/ic_add_white_24dp" />
<TextView
android:id="#+id/countdownfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:backgroundTint="#color/PIBLUE"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/PIBLUE"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:popupTheme="#color/PIBLUE"
tools:layout_editor_absoluteY="-57dp" />
<ListView
android:id="#+id/listview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="#+id/countdownfield"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
and the XML of the listentry
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:longClickable="true"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<TextView
android:id="#+id/textViewToken"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="124891"
android:textSize="28sp"
android:textStyle="bold"
tools:layout_editor_absoluteY="0dp"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent" />
<!-- android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"-->
<TextView
android:id="#+id/textViewLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="privacyidea something"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="#+id/textViewToken"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="#+id/textViewLabel"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.517"
/>
</android.support.constraint.ConstraintLayout>
the part of the MainActivity.java
final ListView listview = (ListView) findViewById(R.id.listview);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(view.getContext(), "SHORT itemclick", Toast.LENGTH_SHORT).show();
}
});
registerForContextMenu(listview);
and the getview method from my custom adapter:
#Override
public View getView(final int position, View v, ViewGroup parent) {
if (v == null) {
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
v = inflater.inflate(R.layout.tokenentry, parent, false);
}
v.setLongClickable(true);
v.setTag(position);
final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.progressBar);
final Token token = getItem(position);
final TextView tmp2 = (TextView) v.findViewById(R.id.textViewToken);
final TextView tmp1 = (TextView) v.findViewById(R.id.textViewLabel);
if (token.getType().equals(HOTP)) {
progressBar.setVisibility(GONE);
} else {
progressBar.setVisibility(VISIBLE);
//v.setClickable(false);
}
progressBar.setTag(position);
progressBar.setMax(token.getPeriod());
progressBar.getProgressDrawable().setColorFilter(
Color.rgb(0x83, 0xc9, 0x27), android.graphics.PorterDuff.Mode.SRC_IN);
token.setPb(progressBar);
tmp1.setText(token.getLabel());
tmp2.setText(token.getCurrentOTP());
EDIT: thank you for taking your time to post answers.
Ive solved the/my problem: the rootelement of the listentries was a contraintlayout and that doesn't seem to work properly with the scenarios i want, so i changed it so a relativelayout and it now it works perfectly!
hi Cxc the problem might be due to listView registered for both onClick and onLongClick . So instead of setting the onClickListener for the entire list view try setting the onClick listener to only the item view for which you need both onClickListener and long click.
You can set onClickListener to particular views inside getView() method based on their position or view type.
for example,
#Override
public View getView(final int position, View v, ViewGroup parent) {
if (v == null) {
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
v = inflater.inflate(R.layout.tokenentry, parent, false);
}
v.setLongClickable(true);
v.setTag(position);
if(position % 2 == 0)
{
v.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(v.getContext(), "SHORT itemclick",
Toast.LENGTH_SHORT).show();
}
});
hope this helps
I think you can use both onClick and onLongClick and override the onLongClick method making it returns true to avoid conflict of triggering onClick event
ex:
GridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
<do somthing here>
}
});
GridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> adapterView, final View view, final int i, long l) {
<do something here>
return true;
}
});
Im trying to add an ImageButton to each row in my ListView (which I implemented via CustomAdapter). Each button should open a different WebView. I can't seem to find any tutorials to do this so any advice/tips/links would be highly apreciated.
EDIT 1:
My Listview XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_x="15dp">
<ImageView
android:layout_width="30dp"
app:srcCompat="#drawable/a"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:id="#+id/local"
android:layout_height="30dp"
android:layout_alignBottom="#+id/versus"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/resultsiz"
android:textColor="#android:color/white"
android:textStyle="normal|bold"
android:gravity="center_vertical"
android:elevation="15dp"
android:layout_alignBaseline="#+id/resultsde"
android:layout_alignBottom="#+id/resultsde"
android:layout_alignRight="#+id/resultsde"
android:layout_alignEnd="#+id/resultsde"
android:layout_marginRight="61dp"
android:layout_marginEnd="61dp" />
<ImageView
android:layout_width="15dp"
app:srcCompat="#drawable/a"
android:id="#+id/versus"
android:layout_height="15dp"
android:layout_marginLeft="31dp"
android:layout_marginStart="31dp"
android:layout_alignBottom="#+id/visit"
android:layout_toRightOf="#+id/local"
android:layout_toEndOf="#+id/local" />
<ImageView
android:layout_width="30dp"
app:srcCompat="#drawable/a"
android:id="#+id/visit"
android:layout_height="30dp"
android:layout_marginLeft="19dp"
android:layout_marginStart="19dp"
android:layout_alignBottom="#+id/resultsiz"
android:layout_toRightOf="#+id/versus"
android:layout_toEndOf="#+id/versus" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/local"
android:layout_alignStart="#+id/local"
android:id="#+id/dia"
android:textColor="#color/white"
android:textStyle="normal|bold"
android:textAllCaps="true" />
<TextView
android:text="TextView"
android:layout_height="wrap_content"
android:id="#+id/resultsde"
android:layout_marginRight="24dp"
android:layout_marginEnd="24dp"
android:textColor="#android:color/white"
android:layout_marginTop="19dp"
android:textStyle="normal|bold"
android:textAlignment="viewEnd"
android:gravity="end"
android:layout_width="70dp"
android:layout_below="#+id/dia"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/local"
android:layout_toRightOf="#+id/local"
android:layout_toEndOf="#+id/local"
android:layout_marginTop="155dp"
android:id="#+id/stats" />
</RelativeLayout>
And my CustomAdapter:
protected void onPostExecute(Void aVoid) {
CustomAdapter customAdapter = new CustomAdapter();
lista.setAdapter(customAdapter);
}
class CustomAdapter extends BaseAdapter{
#Override
public int getCount() {
return resultsizq.length;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
view = getLayoutInflater().inflate(R.layout.customlayout,null);
ImageView versus = (ImageView)view.findViewById(R.id.versus);
ImageView local = (ImageView)view.findViewById(R.id.local);
ImageView visit = (ImageView)view.findViewById(R.id.visit);
TextView dia= (TextView)view.findViewById(R.id.dia);
TextView resultsiz= (TextView)view.findViewById(R.id.resultsiz);
TextView resultsde= (TextView)view.findViewById(R.id.resultsde);
dia.setText(di[position]);
resultsiz.setText(resultsizq[position]);
resultsde.setText(resultsder[position]);
versus.setImageResource(versu[position]);
local.setImageResource(loc[position]);
visit.setImageResource(vis[position]);
if ((position+1)%4==0){
view.setPadding(0,0,0,150);
}
if ((position)%4==0){
view.setPadding(0,150,0,0);
}
return view;
}}
In the getView method, you should assign the onClick function to the Button according to the given position. Probably, you should get the item located at position, generate some url based on the properties of this item, and let this url be opened in the onClick function.
More than that, I have 3 suggestions to improve your code:
Try to use RecyclerView instead of ListView.
Even if you use ListView, have a look at View Holder pattern. This is a good place to start.
Consider using Butterknife, which increases the readability of your code. If I were you, I would keep the item as a property in the view holder object, which has a function annotated with #OnClick(R.id.stats) so that it opens the preferred WebView accordingly.
I hope these help.
When I add an item below the "ADD ITEM BELOW" comment as shown below, my onItemLongClick and ListItemClick cannot work. However once I've removed the items below the "ADD ITEM BELOW", it will work. What's wrong?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/caldroid_transparent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/event_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/event_list_margin"
android:layout_marginBottom="#dimen/event_list_margin"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:orientation="vertical"
android:layout_marginLeft="#dimen/standard_margin_size">
<TextView
android:id="#+id/event_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20"
android:gravity="center"
android:layout_centerHorizontal="true"
android:textColor="#color/caldroid_black"
android:textSize="45dp" />
<TextView
android:id="#+id/event_month_year"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="JAN 2015"
android:textSize="12dp"
android:gravity="center"
android:layout_below="#id/event_day"
android:textColor="#color/caldroid_black" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="#dimen/standard_padding_size"
android:paddingBottom="#dimen/standard_padding_size"
android:paddingLeft="#dimen/feed_item_profile_info_padd"
android:paddingRight="#dimen/feed_item_profile_info_padd"
android:layout_marginLeft="#dimen/feed_item_profile_info_padd"
android:layout_marginRight="#dimen/feed_item_profile_info_padd"
android:id="#+id/event_set_colour">
<TextView
android:id="#+id/event_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold"
android:textColor="#color/caldroid_black"
android:textSize="#dimen/standard_text_size" />
<TextView
android:id="#+id/event_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="local"
android:layout_below="#id/event_title"
android:textColor="#color/caldroid_black"
android:textSize="#dimen/feed_item_profile_name" />
<TextView
android:id="#+id/event_start_end_time"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/event_location"
android:text="28 May 2015, Saturday"
android:textColor="#color/caldroid_black"
android:textSize="#dimen/feed_item_profile_name" />
</RelativeLayout>
</LinearLayout>
<!-- ADD ITEM BELOW -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
EventFragment.java
public class EventFragment extends ListFragment {
//Set database to allow user to retrieve data to populate EventFragment.java
private AppointmentController appointmentDatabase;
//List to get all the appointments
private List<Appointment> allAppointment;
EventAdapter adapter;
Appointment selected_appointment;
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get all the appointment
appointmentDatabase = new AppointmentController(getActivity());
appointmentDatabase.open();
allAppointment = appointmentDatabase.getAllAppointment();
//Initialise ArrayAdapter adapter for view
adapter = new EventAdapter(getActivity(), R.layout.row_event, allAppointment);
setListAdapter(adapter);
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View view, int position, long id) {
// remove code for simplicity
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_listfragment, container, false);
return rootView;
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// remove code for simplicity
}
If you wants to make onItemClick work add
android:descendantFocusability="blocksDescendants"
to the parent layout something like it:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/caldroid_transparent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
</LinearLayout>
when you blocksDescendants then you can not get onClick event on
Button in row of ListView. Basically you can get event on either row
or Button in a row.
Try changing:
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// remove code for simplicity
}
to
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public boolean onItemClick(AdapterView<?> arg0, View view, int position, long id) {
// whatever code would have been above put in here
}
all my views and non focusable and non clickable except the switch which is clickable but making it non clickable still doesn't make the list view fire
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/timed_events_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="false"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/event_name"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:textSize="20sp"
android:textStyle="bold"
android:singleLine="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
/>
<TextView
android:id="#+id/event_time"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:singleLine="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
/>
</LinearLayout>
<Switch
android:id="#+id/state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:onClick="isActivated"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</RelativeLayout>
below is the OnItemSelectedListener which is in the onCreate method
listView.setOnItemSelectedListener( new OnItemSelectedListener(){
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(ActivityContext, "its working", Toast.LENGTH_LONG).show();
Intent intent ;
if(listAdapter.getItemViewType(position) == 1){
intent = new Intent(ActivityContext,Volume.class);
Volume.currentPref((SoundDetails) timers.get(position),position);
} else{
intent = new Intent(ActivityContext,Message.class);
Message.currentMessage((MessageListDetails) timers.get(position),position);
}
startActivity(intent);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}});
For ListView you need to set onItemClickListener instead of onItemSelectedListener
chanage like this..
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// perform your operation
}
});
i have a custom listview in that, i have text field and check box. when i click on the list view the check box should be enable if it is not enable and vice visa. it is possible in android?
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
my listview is below.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:focusable="false"
android:textColor="#color/white"
android:focusableInTouchMode="false"
android:text="CheckBox" />
<TextView
android:id="#+id/code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/checkBox1"
android:layout_alignBottom="#+id/checkBox1"
android:visibility="invisible"
android:textColor="#color/white"
android:layout_toRightOf="#+id/checkBox1"
android:text="TextView" />
this is my list in main activity xml
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
1) You need an onItemClickListener
2) get the CheckBox
3) set the CheckBox to the opposite if its current status
4) done :)
listView.onItemClickListener(new OnItemClickListener(){
public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3){
CheckBox checkBox = v.findViewById(R.id.checkBox1);
checkBox.setChecked(!checkBox.isChecked());
}
});
You already have the listener that reacts, when someone clicks on a list-item.
The View that is given in the method onItemClick is the list-item.
Now you just need to get the CheckBox from the list-item:
final CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox1);
And then you can check, if it's checked with isChecked() and set it with setChecked().