内のすべてのキーデータを取得し、私はスピナーにJSONをパースしていますが、私はスピナースピナー
の最後の鍵データを取得し、以下onPostExecute方法でいスピナー内のすべてのデータ、 を取得しておりません。私は次のクラスすなわちPut_Credentials.javaする意図を経由してアレイを送っています。..
からこれは私の完全なJSONです:
[
[
{
"User_Id": "PANKAJ",
"Password": "31184555",
"teacher_id": "24",
"teacher_name": "MR. PANKAJ SINGH",
"msg": "Successfully Login"
}
],
[
{
"Batch_Id": "1",
"Batch": "2016-21"
},
{
"Batch_Id": "2",
"Batch": "2015-20"
},
{
"Batch_Id": "3",
"Batch": "2014-19"
},
{
"Batch_Id": "4",
"Batch": "2013-18"
},
{
"Batch_Id": "5",
"Batch": "2012-17"
},
{
"Batch_Id": "6",
"Batch": "2014-17"
},
{
"Batch_Id": "7",
"Batch": "2015-18"
},
{
"Batch_Id": "8",
"Batch": "2016-19"
}
],
[
{
"Section_Id": "1",
"Section_Name": "A"
},
{
"Section_Id": "2",
"Section_Name": "B"
},
{
"Section_Id": "3",
"Section_Name": "C"
},
{
"Section_Id": "4",
"Section_Name": "D"
},
{
"Section_Id": "5",
"Section_Name": "E"
}
],
[
{
"subject_id": "1",
"subject_name": "English-I"
},
{
"subject_id": "2",
"subject_name": "English III"
},
{
"subject_id": "3",
"subject_name": "Jurisprudence"
},
{
"subject_id": "4",
"subject_name": "Company Law"
},
{
"subject_id": "5",
"subject_name": "Law of Evidence"
},
{
"subject_id": "6",
"subject_name": "Sociology-I"
},
{
"subject_id": "7",
"subject_name": "Hindi -I"
}
]
]
______________ +++++++++++++ +++++++++++++++++++++++++++++++++ ____________________________
これは私のLogin_Activityです。ここで
結果は、ここで私はPutCredentials.javaクラスにデータを送信しています
@Override
protected void onPostExecute(String result) {
try {
if (progress != null) {
progress.dismiss();
}
JSONArray jsonArray = new JSONArray(result);
jsonArrayTeacherName = jsonArray.getJSONArray(0);
jsonArrayBatch = jsonArray.getJSONArray(1);
jsonArraySection = jsonArray.getJSONArray(2);
jsonArraySubject = jsonArray.getJSONArray(3);
JSONObject jsonResponse = jsonArrayTeacherName.getJSONObject(0);
teachername = jsonResponse.getString("teacher_name");
batch = jsonArrayBatch.toString();
section = jsonArraySection.toString();
subject = jsonArraySubject.toString();
`Intent i = new Intent(Login_activity.this, PutCredentials.class);
i.putExtra("BATCH_ARRAY", jsonArrayBatch.toString());
i.putExtra("SECTION_ARRAY", jsonArraySection.toString());
i.putExtra("SUBJECT_ARRAY", jsonArraySubject.toString());
i.putExtra("Password",Password);
i.putExtra("User_Id", Idcardno);
i.putExtra("login_id", loginId);
i.putExtra("teacher_name", teachername);
startActivity(i);
}
catch (JSONException e) {
Log.e("MainActivity", "unexpected JSON exception", e);
}
// Toast.makeText(getBaseContext(), "Data Sent!", Toast.LENGTH_LONG).show();
}`
から_____________________________ +++++ ___________________________________
... JSONから見つかった(上図)完全な配列であり、ここでは、ログインアクティビティからデータを取得しています。
PutCredentials.Java:
public class PutCredentials extends Activity {
ProgressDialog progress;
TextView TVTeacherName;
String Password, Idcardno, loginId, teachername, teacherid;
Button submit;
Spinner batchSpinner, sectionSpinner, subjectSpinner;
ArrayList<String> batchlist;
ArrayList<String> sectionlist;
ArrayList<String> subjectlist;
String jsonArrayForBatch;
String jsonArrayForSection;
String jsonArrayForSubject;
String batchdata, sectiondata, subjectdata;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_put_credentials);
TVTeacherName = (TextView) findViewById(R.id.tv_teachername);
submit = (Button) findViewById(R.id.button_submit);
batchSpinner = (Spinner) findViewById(R.id.batch_spinner);
sectionSpinner = (Spinner) findViewById(R.id.section_spinner);
subjectSpinner = (Spinner) findViewById(R.id.subject_spinner);
Intent intent = getIntent();
jsonArrayForBatch = intent.getStringExtra("BATCH_ARRAY");
jsonArrayForSection = intent.getStringExtra("SECTION_ARRAY");
jsonArrayForSubject = intent.getStringExtra("SUBJECT_ARRAY");
Password = intent.getExtras().getString("Password");
Idcardno = intent.getExtras().getString("User_Id");
loginId = intent.getExtras().getString("login_id");
teachername = intent.getExtras().getString("teacher_name");
getBatchSpinner();
getSectionSpinner();
getSubjectSpinner();
TVTeacherName.setText(teachername);
dateView = (TextView) findViewById(R.id.date);
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
showDate(year, month+1, day);
});
}
private void getBatchSpinner(){
try {
JSONArray jArray = new JSONArray(jsonArrayForBatch);
JSONObject j = null;
for (int i = 0; i < jArray.length(); i++) {
j = jArray.getJSONObject(i);
if (j != null) {
batchdata = j.optString("Batch");
}
batchlist = new ArrayList<String>();
batchlist.add(batchdata);
}
batchSpinner
.setAdapter(new ArrayAdapter<String>(PutCredentials.this,
android.R.layout.simple_spinner_dropdown_item,
batchlist));
} catch (JSONException e) {
e.printStackTrace();
}
}
private void getSectionSpinner(){
try {
JSONArray jArray = new JSONArray(jsonArrayForSection);
for (int i = 0; i<jArray.length(); i++) {
JSONObject j = jArray.getJSONObject(i);
sectiondata = j.optString("Section_Name");
sectionlist = new ArrayList<String>();
sectionlist.add(sectiondata);
}
sectionSpinner
.setAdapter(new ArrayAdapter<String>(PutCredentials.this,
android.R.layout.simple_spinner_dropdown_item,
sectionlist));
} catch (JSONException e) {
e.printStackTrace();
}
}
private void getSubjectSpinner(){
try {
JSONArray jArraySubject = new JSONArray(jsonArrayForSubject);
for (int i = 0; i<jArraySubject.length(); i++) {
final JSONObject jsonObjectBatch = jArraySubject.getJSONObject(i);
subjectdata = jsonObjectBatch.optString("subject_name");
subjectlist = new ArrayList<String>();
subjectlist.add(subjectdata);
subjectSpinner
.setAdapter(new ArrayAdapter<String>(PutCredentials.this,
android.R.layout.simple_spinner_dropdown_item,
subjectlist));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
は今私の問題は私のスピナーは、JSON、すなわち2016年から2019年、Eとヒンディー語-1で最後の場所でのみBtches、セクションと被験者を示していること、です。 このSpinnerには、Spinnerの「Section_Name」、つまり「E」の最後の値が表示されています。 Spinnerのキー "Batch" "Section_Name"と "Subject_Name"のすべての値を取得するにはどうしたらいいですか?
明らかに、文字列 – Selvin
の代わりにPOJOでアダプタを使用する必要があります。同じ変数に何度も繰り返し格納しています。 'List'または 'String []' –
0xDEADC0DE
Googleがそれらのことについてたくさん知っている必要があります。 – 0xDEADC0DE