-
-
Save tatd3v/e7cb0e91f29d9c333201b1b4e93cac2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListActivity extends AppCompatActivity { | |
PatientController pC; | |
ListView pList; | |
PatientCursorAdapter pca; | |
Patient pat; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_list); | |
pList = findViewById(R.id.infoListLV); | |
pC = new PatientController(getApplicationContext()); | |
Cursor c = pC.allPatients(); | |
pca = new PatientCursorAdapter(this, c, 0); | |
pList.setAdapter(pca); | |
pca.notifyDataSetChanged(); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.list_activity_toolbar, menu); | |
return super.onCreateOptionsMenu(menu); | |
} | |
@Override | |
public boolean onOptionsItemSelected(@NonNull MenuItem item) { | |
switch (item.getItemId()){ | |
case R.id.edit: | |
List<String> selectedIdsList = pca.getSelectedIdsList(); | |
// recorrer la lista y hacer lo que necesites hacer con esos IDs | |
return true; | |
case R.id.delete: | |
List<String> selectedIdsList = pca.getSelectedIdsList(); | |
// recorrer la lista y hacer lo que necesites hacer con esos IDs | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TodoCursorAdapter extends CursorAdapter { | |
List<String> selectedIdsList = new ArrayList<>(); | |
public TodoCursorAdapter(Context context, Cursor cursor) { | |
// ... | |
} | |
@Override | |
public View newView(Context context, Cursor cursor, ViewGroup parent) { | |
// ... | |
} | |
@Override | |
public void bindView(View view, Context context, Cursor cursor) { | |
Checkbox checkbox = (Checkbox) view.findViewById(R.id.checkbox); | |
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener{ | |
@Override | |
public onChecked(View view, boolean checked) { | |
String id = cursor.getString(cursor.getColumnIndexOrThrow("id")); | |
if (checked) { | |
selectedIdsList.add(id); | |
} else { | |
selectedIdsList.remove(id); | |
} | |
} | |
}); | |
} | |
public List<String> getSelectedIdsList() { | |
return selectedIdsList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment