Just trying to create a simple app that would allow users to input notes and save them into the List view. What code would I need to implement to allow the user to longClick something in the list to delete it.
public class Notes extends AppCompatActivity {
Button save;
ArrayList<String> addArray = new ArrayList<String>();
EditText txt;
ListView show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notes);
txt = (EditText) findViewById(R.id.textInput);
show = (ListView) findViewById(R.id.listView);
save = (Button) findViewById(R.id.saveButton);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(Notes.this, android.R.layout.simple_list_item_1, addArray);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String getInput = txt.getText().toString();
if (addArray.contains(getInput)) {
Toast.makeText(getBaseContext(), "Note already added!", Toast.LENGTH_LONG).show();
} else if (getInput == null || getInput.trim().equals("")) {
Toast.makeText(getBaseContext(), "Input required!", Toast.LENGTH_LONG).show();
} else {
addArray.add(getInput);
show.setAdapter(adapter);
((EditText) findViewById(R.id.textInput)).setText(" ");
}
}
});
show.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
return true;
}
});
}
}