Ich mache derzeit eine App, wo der Benutzer Studienmaterial aus einer Listenansicht von verschiedenen Themen zugreifen kann.Inhalt der Online-Server-Datei auf Android-App anzeigen
In meiner Datenbanktabelle, aus der die Subjektnamen abgerufen werden, hat auch eine Spalte, die einen Dateipfad zu einem Ordner auf meinem Online-Server hat. Jeder Betreff hat einen eigenen Ordner auf dem Server.
Wie würde ich meinem Code hinzufügen, sodass der Inhalt eines bestimmten Ordners bei einer neuen Aktivität angezeigt wird, wenn ein Benutzer auf ein Thema in der Liste klickt?
hier ist mein Code zur Zeit einer einfachen Listenansicht:
public class FindMaterialActivity extends Activity {
private ListView list;
private ArrayList<String> subjects;
private JSONArray result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_material2);
list = (ListView) findViewById(R.id.list);
subjects = new ArrayList<String>();
getData();
}
private void getData() {
//Creating a string request
StringRequest stringRequest = new StringRequest(SubConfig.DATA_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject j = null;
try {
//Parsing the fetched Json String to JSON Object
j = new JSONObject(response);
//Storing the Array of JSON String to our JSON Array
result = j.getJSONArray(SubConfig.JSON_ARRAY);
//Calling method getStudents to get the students from the JSON Array
getSubjects(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating a request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
private void getSubjects(JSONArray j) {
//Traversing through all the items in the json array
for (int i = 0; i < j.length(); i++) {
try {
//Getting json object
JSONObject json = j.getJSONObject(i);
//Adding the name of the student to array list
subjects.add(json.getString(SubConfig.TAG_SUBJECTS));
} catch (JSONException e) {
e.printStackTrace();
}
}
//Setting adapter to show the items in the spinner
list.setAdapter(new ArrayAdapter<String>(FindMaterialActivity.this, android.R.layout.simple_list_item_1, subjects));
}
}
und unterliegen config.java
public class SubConfig {
//JSON URL
public static final String DATA_URL = "http://opuna.co.uk/subject_api/FetchSub.php";
//Tags used in the JSON String
public static final String TAG_SUBJECTS = "Subject_Name";
public static final String TAG_SUB_ID = "Sub_id";
//JSON array name
public static final String JSON_ARRAY = "result";
}