current Uni student and i am trying to create a custom array adapter class that extends the ArrayAdapter class so i can disable clicks on selected items in the list view.
I am unsure how to implement this new class this is what i have so far
package com.example.assignment1;
import android.content.Context;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
public class customAdapter extends ArrayAdapter {
public customAdapter(@NonNull Context context, int resource) {
super(context, resource);
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int position) {
// return super.isEnabled(position);
}
}
I am unsure how to write the isEnabled function as well:
this is how i intend to use this function
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
poss = position + 1;
AlertDialog.Builder builder = new AlertDialog.Builder(viewFriends.this);
builder.setTitle("Notice");
builder.setMessage("Please select to to edit, delete a friend or cancel");
// add the buttons
builder.setPositiveButton("Edit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//System.out.println(poss);
Intent intent = new Intent(getApplicationContext(), editOrDelete.class);
ArrayList<String> result1 = mydb.retrieveRow(poss);
name = result1.get(1);
age = result1.get(2);
gender = result1.get(3);
address = result1.get(4);
code = result1.get(0);
intent.putExtra("code", code);
intent.putExtra("name", name);
intent.putExtra("age", age);
intent.putExtra("gender", gender);
intent.putExtra("address", address);
startActivity(intent);
}
});
builder.setNeutralButton(" Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
System.out.println(poss);
mydb.updateDeleted(poss);
if(listView.getChildAt(position).isEnabled())
{
listView.getChildAt(position).setEnabled(false);
// function to disable clicks
}
}
});
builder.setNegativeButton("Cancel", null);
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
public void displayFriendList() {
ArrayList<String> result = mydb.retrieveRows();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, result);
listView.setAdapter(adapter);
}
so when the user clicks the delete button from the alert i would like to grey out the item they clicked on in the list view (i managed to achieve this) but i would also like for it not to be able to be clicked on once it has been deleted
and suggestions on how i can achieve this?