i am working with custom listview with checkbox , so i did everything well , but now i am stuck in some point , my question is how to handle with the checked elements and how i get theire position
my mainActivity:
public class MainActivity extends AppCompatActivity{
ListView listView;
ArrayAdapter<Universities> adapter;
Button btn_done;
public static ArrayList<Universities> listOfuniversities ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listOfuniversities = new ArrayList<Universities>(50);
addUnivs(1); //this fuction add items on my list view
listView = findViewById(R.id.myListView);
adapter = new UniversityAdapter(this ,listOfuniversities);
listView.setAdapter(adapter);
btn_done = findViewById(R.id.btndone);
}
my array adapter :
public class UniversityAdapter extends ArrayAdapter<Universities> {
CheckBox mycheck_box;
Context context;
ArrayList<Universities> Univerisyyy;
TextView nom_uv , state_uv , spec_uv , req_rate_uv , duration_uv , reputation_uv , joboffers_uv
, sholarchip_uv , cost_uv;
String nom_univ ="--", satae_univ ="--", speciality_univ ="--",RequiredRate_univ ="--"
, Duration_of_study_univ ="--", Reputation_univ="--" ,JobOffers_univ="--"
, Scholarshipoffers_univ="--";
float Cost_univ = 1;
Universities myUniversity;
UniversityAdapter(Context context , ArrayList<Universities> Univerisyyy){
super(context ,0, Univerisyyy );
this.context = context;
this.Univerisyyy= Univerisyyy;
}
Context mContext = context;
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItemView = LayoutInflater.from(getContext()).inflate(R.layout.row , parent , false);
myUniversity = getItem(position);
nom_univ = myUniversity.nom_univ;
satae_univ = myUniversity.satae_univ;
speciality_univ = myUniversity.speciality_univ;
RequiredRate_univ = myUniversity.RequiredRate_univ;
Duration_of_study_univ = myUniversity.Duration_of_study_univ;
Reputation_univ = myUniversity.Reputation_univ;
JobOffers_univ = myUniversity.JobOffers_univ;
Scholarshipoffers_univ = myUniversity.Scholarshipoffers_univ;
Cost_univ = myUniversity.Cost_univ;
nom_uv = listItemView.findViewById(R.id.Name_univ);
nom_uv.setText(nom_univ);
state_uv = listItemView.findViewById(R.id.state_univ);
state_uv.setText(satae_univ);
spec_uv = listItemView.findViewById(R.id.Speciality_univ);
spec_uv.setText(speciality_univ);
req_rate_uv = listItemView.findViewById(R.id.Required_Rate_univ);
req_rate_uv.setText(RequiredRate_univ);
duration_uv = listItemView.findViewById(R.id.Duration_of_study_univ);
duration_uv.setText(Duration_of_study_univ);
cost_uv = listItemView.findViewById(R.id.Cost_univ);
String c = String.valueOf(Cost_univ);
cost_uv.setText(c);
reputation_uv = listItemView.findViewById(R.id.Reputation_univ);
reputation_uv.setText(Reputation_univ);
joboffers_uv = listItemView.findViewById(R.id.Job_Offers_univ);
joboffers_uv.setText(JobOffers_univ);
sholarchip_uv = listItemView.findViewById(R.id.Scholarship_offers_univ);
sholarchip_uv.setText(Scholarshipoffers_univ);
mycheck_box = listItemView.findViewById(R.id.checkbox_univ);
//this is mycheck box
return listItemView;
} }
and, Is there a way to collect the check elements in Arraylist which contain their position ?
Aucun commentaire:
Enregistrer un commentaire