2017-02-23 244 views
-2

Я могу разобрать имя, указав индивидуальный идентификатор в URL-адресе (http://192.168.100.5:84/api/academics/students/1 здесь 1 is id). Обычно, когда я вхожу в систему, ему нужны имя пользователя и пароль, а затем Intent to Next Page.Then у меня есть настройка навигации Ящик, который должен быть динамическим в имени пользователя, поскольку имя пользователя для входа отличается, тогда имя на навигационном ящике должно быть изменено.Анализ данных JSON с использованием идентификатора с помощью Volley?

Главная Класс

public class Home extends AppCompatActivity implements View.OnClickListener { 


    LinearLayout calendar, classSchedule, progressReport, profile, fee, dshboard, setting, logout, attendance; 
    android.support.v4.app.FragmentManager fragmentManager; 
    public static final String Navigation_URL = "http://192.168.100.5:84/api/academics/students/1"; 
    ImageView studentprofileimage; 
    TextView profilename; 

    @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_dashboard); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     studentprofileimage = (ImageView) findViewById(R.id.avatar);//initilise student name 
     profilename = (TextView) findViewById(R.id.profilename);// student profile name 


     dshboard = (LinearLayout) findViewById(R.id.dashboard_layout); 
     calendar = (LinearLayout) findViewById(R.id.calender_layout); 
     fee = (LinearLayout) findViewById(R.id.view_fee); 
     classSchedule = (LinearLayout) findViewById(R.id.class_schedule); 
     progressReport = (LinearLayout) findViewById(R.id.progress_report); 
     profile = (LinearLayout) findViewById(R.id.view_profile); 
     setting = (LinearLayout) findViewById(R.id.mainsetting); 
     logout = (LinearLayout) findViewById(R.id.mainlogout); 
     attendance = (LinearLayout) findViewById(R.id.class_attendance); 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 

     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
     navigationView.setVisibility(View.VISIBLE); 

     calendar.setOnClickListener(this); 
     classSchedule.setOnClickListener(this); 
     fee.setOnClickListener(this); 
     dshboard.setOnClickListener(this); 
     progressReport.setOnClickListener(this); 
     profile.setOnClickListener(this); 
     setting.setOnClickListener(this); 
     logout.setOnClickListener(this); 
     attendance.setOnClickListener(this); 
     FragmentTransaction tx = getSupportFragmentManager().beginTransaction(); 
     tx.replace(R.id.container, new Dashboard()); 
     tx.commit(); 
     makeJsonObjectRequest(); 

    } 


    private void makeJsonObjectRequest() { 

     StringRequest stringRequest = new StringRequest(Request.Method.GET, Navigation_URL, 
       new Response.Listener<String>() { 
        @Override 
        public void onResponse(String response) { 
         try { 
          JSONObject jsonObject = new JSONObject(response); 
          StudentInformation studentInformation = new StudentInformation(); 
          studentInformation.Name = jsonObject.getString("NAME"); 
          profilename.setText(studentInformation.Name); 
         } catch (JSONException e) { 
          Toast.makeText(getApplicationContext(), "Fetch failed!", Toast.LENGTH_SHORT).show(); 
          e.printStackTrace(); 
         } 

        } 

       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 
         Toast.makeText(Home.this, error.toString(), Toast.LENGTH_LONG).show(); 
        } 
       }); 
     RequestQueue requestQueue = Volley.newRequestQueue(this); 
     requestQueue.add(stringRequest); 


    } 

я разобран только это

{ 

    "StdID":1, 
    "NAME":"Kirsten Green", 
    "PHONENO":"095-517-0049", 
    "DOB":"2009-12-28T00:00:00", 
    "CLASS":9, 
    "GENDER":"M", 
    "ADDRESS":"8254 At Ave"} 

я путаюсь, что бы логика в домашнем классе, как изменения имени пользователя, то имя на ящик должен изменить , На самом деле гиперссылка должна быть http://192.168.100.5:84/api/academics/students

{ 

    "StdID":14, 
    "NAME":"Thaddeus Lewis", 
    "PHONENO":"025-718-3841", 
    "DOB":"2016-04-12T00:00:00", 
    "CLASS":8, 
    "GENDER":"a", 
    "ADDRESS":"6024 Scelerisque Rd.", 
    "NATIONALITY":"Liberia", 
    "ENROLLEDYEAR":"2017-03-02T00:00:00", 
    "Photo":null, 
    "Cat_ID":5, 
    "base64":null, 
    "studentDetails":{ 
     "StdID":14, 
     "GUARDIAN_PHONE_NO":"090-996-4913", 
     "MOBILE_NO":"1-931-439-7550", 
     "First_NAME":"Kitra", 
     "Last_Name":"Walls", 
     "Relation":"vehicula risus. Nulla eget met", 
     "DOB":"2017-09-23T00:00:00", 
     "Education":"malesuada augue ut lacus. Null", 
     "Occupation":"urna suscipit nonummy.", 
     "Income":"€135,759", 
     "Email":"[email protected]", 
     "AddLine1":"496-5045 Ligula Rd.", 
     "AddLine2":"426-283 Aenean Street", 
     "State":"MAR", 
     "Country":"Heard Island and Mcd" 
    }, 
    "Marks":null, 
    "stdCategory":{ 
     "Cat_ID":5, 
     "Category":"Normal" 
    } 

}, 
{ 

    "StdID":15, 
    "NAME":"Roanna Ramirez", 
    "PHONENO":"087-467-8647", 
    "DOB":"2016-04-09T00:00:00", 
    "CLASS":4, 
    "GENDER":"a", 
    "ADDRESS":"9620 Aliquam Ave", 
    "NATIONALITY":"Portugal", 
    "ENROLLEDYEAR":"2017-08-03T00:00:00", 
    "Photo":null, 
    "Cat_ID":5, 
    "base64":null, 
    "studentDetails":{ 
     "StdID":15, 
     "GUARDIAN_PHONE_NO":"002-444-8345", 
     "MOBILE_NO":"1-948-383-0527", 
     "First_NAME":"Mari", 
     "Last_Name":"Mendez", 
     "Relation":"Cras convallis", 
     "DOB":"2017-08-20T00:00:00", 
     "Education":"luctus lobortis. Class aptent ", 
     "Occupation":"mi fringilla mi lacinia mattis", 
     "Income":"€112,474", 
     "Email":"[email protected]", 
     "AddLine1":"Ap #203-6706 Gravida St.", 
     "AddLine2":"Ap #416-2961 Dis Avenue", 
     "State":"MI", 
     "Country":"Morocco" 
    }, 
    "Marks":null, 
    "stdCategory":{ 
     "Cat_ID":5, 
     "Category":"Normal" 
    } 

} 
+0

View view = navigationView.getHeaderView (0); final TextView username = (TextView) view.findViewById (R.id.drawer_username); username.setText («username»), где headerview содержит часть заголовка ящика –

ответ

0

я столкнулась аналогичный вопрос: Вы можете разобрать эти данные в ящике класса это сам, где вы можете получить доступ к TextView имени профиля. Включите синтаксический анализ и настройку кода текстового поля в onCreate вашего класса ящика.

+0

, можете ли вы предоставить некоторый фрагмент кода – seon