Дорогие друзья , я хочу получить значение данных массива json из индекса и сравнить с моим идентификатором магазина.Например:
я хочу получить instituteID из массива json и сравнить со значением «3», а если оно истинно, отобразить сохраненное значение темы в textview if (instituteID == 3) {tv.setText (subject);} instituteID и тема также приходят от json. Скажите, где я не прав
ArrayList<HashMap<String,String>> arraylist = new ArrayList<>();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView)findViewById(R.id.subject1);
tv2 = (TextView)findViewById(R.id.subject2);
tv3 = (TextView)findViewById(R.id.subject3);
tv4 = (TextView)findViewById(R.id.subject4);
tv5 = (TextView)findViewById(R.id.subject5);
tv6 = (TextView)findViewById(R.id.subject6);
//here calling json asynctask
new getTacherJson().execute();
DisplayData();
}
public void DisplayData(){
SharedPreferences preferences = getSharedPreferences("Email's response",MODE_PRIVATE);
shared_pref_emal = preferences.getString("response",null);
Log.e("Email's response",shared_pref_emal);
SharedPreferences preferences1 = getSharedPreferences("Institute's ID",MODE_PRIVATE);
shared_pref_ins_id = preferences1.getString("response id",null);
Log.e("inst. id",shared_pref_ins_id);
if (institute_ID == shared_pref_ins_id){
tv1.setText(subject);
tv2.setText(subject2);
tv3.setText(subject3);
tv4.setVisibility(View.GONE);
tv5.setVisibility(View.GONE);
tv6.setVisibility(View.GONE);
}
else {
tv1.setText("Nothing");
}
}
//here is my Json Data
{"response":[{"id":"11","class":"One Class","section":"Morning","teacher":"abc@gmail.com","subject":"Urdu","fromTime":"08:00","toTime":"08:30","instituteID":"3","created_at":"2019-09-12 04:39:31"},{"id":"12","class":"One Class","section":"Morning","teacher":"abc@gmail.com","subject":"Pakistan Studies","fromTime":"08:30","toTime":"09:00","instituteID":"3","created_at":"2019-09-12 04:39:49"},{"id":"13","class":"BSSE","section":"Evening","teacher":"abc@gmail.com","subject":"Introduction to CMP","fromTime":"15:00","toTime":"17:30","instituteID":"3","created_at":"2019-09-16 07:39:43"}]}
MyHttpHandler myhttp = new MyHttpHandler();
String teacherURL = url+"/showTeacherCourses/"+get_email+"/"+shared_pref_ins_id;
String teachDash = myhttp.MyServiceCall(teacherURL);
Log.e(TAG,"Response From Teacher Courses"+teachDash);
if (teachDash != null) {
try {
JSONObject jsonObject = new JSONObject(teachDash);
JSONArray teachArray = jsonObject.getJSONArray("response");
Log.e("Array length", String.valueOf(teachArray.length()));
// looping through All Contacts
for (int i = 0; i < teachArray.length(); i++) {
JSONObject c = teachArray.getJSONObject(i);
id1 = c.getString("id");
clasx = c.getString("class");
section = c.getString("section");
teacher_emaill = c.getString("teacher");
subject = c.getString("subject");
from_time = c.getString("fromTime");
to_time = c.getString("toTime");
institute_ID = c.getString("instituteID");
created_at = c.getString("created_at");
HashMap<String, String> tech_dta_ftch = new HashMap<>();
// adding each child node to HashMap key => value
tech_dta_ftch.put("id", id1);
tech_dta_ftch.put("class",clasx);
tech_dta_ftch.put("section",section);
tech_dta_ftch.put("teacher",teacher_emaill);
tech_dta_ftch.put("subject",subject);
tech_dta_ftch.put("fromTime",from_time);
tech_dta_ftch.put("toTime",to_time);
tech_dta_ftch.put("created_at", created_at);
tech_dta_ftch.put("instituteID", institute_ID);
// adding contact to contact list
arraylist.add(tech_dta_ftch);