Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class Cast extends AsyncTask<Object, Void, ArrayList<String>> {
- ProgressDialog dialog;
- @Override
- protected void onPreExecute() {
- // TODO Auto-generated method stub
- super.onPreExecute();
- dialog=new ProgressDialog(Detailed_View.this);
- dialog.setMessage("Loading, please wait");
- dialog.setTitle("Connecting server");
- dialog.show();
- dialog.setCancelable(false);
- }
- private final String KeY = "";
- private static final String DEBUG_TAG = "TM";
- @Override
- protected ArrayList<String> doInBackground(Object... params) {
- try {
- return getCast();
- } catch (IOException e) {
- return null;
- }
- }
- @Override
- protected void onPostExecute(ArrayList<String> results_Cast) {
- updateListOfCast(results_Cast);
- dialog.cancel();
- };
- public ArrayList<String> getCast() throws IOException {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append("https://themovie/3/movie/" + id
- + "/credit");
- stringBuilder.append("?key=" + key);
- URL url = new URL(stringBuilder.toString());
- // Log.d("urlstring",stringBuilder.toString() );
- InputStream stream = null;
- try {
- // Establish a connection
- HttpURLConnection conn = (HttpURLConnection) url
- .openConnection();
- conn.setReadTimeout(10000 /* milliseconds */);
- conn.setConnectTimeout(15000 /* milliseconds */);
- conn.setRequestMethod("GET");
- conn.addRequestProperty("Accept", "application/json"); // Required
- // to
- // get
- // TMDB
- // to
- // play
- // nicely.
- conn.setDoInput(true);
- conn.connect();
- int responseCode = conn.getResponseCode();
- Log.d(DEBUG_TAG, "The response code is: " + responseCode + " "
- + conn.getResponseMessage());
- stream = conn.getInputStream();
- return parseCast(stringify(stream));
- } finally {
- if (stream != null) {
- stream.close();
- }
- }
- }
- private ArrayList<String> parseCast(String result) {
- String streamAsString = result;
- ArrayList<String> results_Cast = new ArrayList<String>();
- try {
- JSONObject jsonObject = new JSONObject(streamAsString);
- JSONArray array = (JSONArray) jsonObject.get("cast");
- Log.d("array view", array.toString());
- for (int i = 0; i < array.length(); i++) {
- HashMap<String, String> map = new HashMap<String, String>();
- JSONObject jsonMovieObject = array.getJSONObject(i);
- results_Cast.add(jsonMovieObject.getString("name"));
- ids=jsonMovieObject.getString("id");
- results_Cast.add(jsonMovieObject.getString("character"));
- }
- } catch (JSONException e) {
- Log.d("e", e.toString());
- Log.d(DEBUG_TAG, "Error parsing JSON. String was: "
- + streamAsString);
- }
- // Log.d("resulted", results_Cast.toString());
- return results_Cast;
- }
- public String stringify(InputStream stream) throws IOException,
- UnsupportedEncodingException {
- Reader reader = null;
- reader = new InputStreamReader(stream, "UTF-8");
- BufferedReader bufferedReader = new BufferedReader(reader);
- return bufferedReader.readLine();
- }
- }
- ListView listView = (ListView) findViewById(R.id.cast_details);
- //Log.d("updateViewWithResults", result.toString());
- // Add results to listView.
- listView.setAdapter(adapter);
- Helper.getListViewSize(listView);
- gridAdapter = new GridAdapter(this, R.layout.test_row, result); // here I have issue.
- listView.setAdapter(gridAdapter);
- listView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long idss) {
- // TODO Auto-generated method stub
- String name = (String) parent.getItemAtPosition(position);
- Toast.makeText(Detailed_View.this, name+"Id"+ids, Toast.LENGTH_SHORT)
- .show();
- }
- });
- public class GridAdapter extends BaseAdapter {
- public GridAdapter(Activity a, int resource, ArrayList<String> result) { // here it displays error as The blank final field itemLists may not have been initialized
- layoutInflater = (LayoutInflater) a
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- Resource = resource;
- results=result;
- activity=a;
- loader=new ImageLoader(a.getApplicationContext());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement