简体   繁体   中英

I have an Object of Array type contains some data. I want to set it to textview with comma seperation

I'm getting response from API. I want to set Array objects to textView with comma seperation or like chips. How can i achieve this? Below is my code

String batch="";
  for (int i=0 ; i < batchModel.getTrainingMode().size() ; i++){
      batch = batchModel.getTrainingMode().get(i).getName();
  }
 tvTrainingModeType.setText(batch);

API response


            "TrainingMode": [
                {
                    "Id": 1,
                    "Name": "Online"
                },
                {
                    "Id": 2,
                    "Name": "Class Room"
                },
                {
                    "Id": 3,
                    "Name": "Certification"
                },
                {
                    "Id": 4,
                    "Name": "Training&Placement"
                },
                {
                    "Id": 5,
                    "Name": "Industrial Training"
                }
            ],

If you want to populate values to one text view, use this.

String result = "";
for(String name : coursesModel.getTrainingMode()){
result += ", " + name;
}

tvTrainingModeType.setText(result)

If you want chip view in android, refer this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM