2016-12-08 4 views
0

こんにちは友人、私はフラグメントのタイトル、画像や評価の3つの値をしたいが、私は新しい活動への断片から4つの値を渡したい..... jsonデータをフラグメントから表示せずにフラグメントからアクティビティに渡す方法は?

www.walnutevolve.com/pic.jpg

===このリンク

[Fragment.javaをチェック]

private static final String TAG = LatestFragment.class.getSimpleName(); 

// Movies json url 
private static final String url = "http://vasundharadeep.news/android/lastest.php?page=1"; 
private ProgressDialog pDialog; 
private List<Movie> movieList = new ArrayList<Movie>(); 
private ListView listView; 
private CustomListAdapter adapter; 

private static String Title="title"; 
private static String Genre="genre"; 
private static String Rating="rating"; 
private static String bitmap="thumbnailUrl"; 
ImageView img; 
ListView list; 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 


    View v = inflater.inflate(R.layout.latest_layout, container, false); 
    //getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); 
    Intent intent2 = new Intent(); 
    getActivity().setResult(Activity.RESULT_OK, intent2); 

    list = (ListView) v.findViewById(R.id.list); 
    img = (ImageView) v.findViewById(R.id.share); 

    adapter = new CustomListAdapter(getActivity(), movieList); 
    list.setAdapter(adapter); 



    pDialog = new ProgressDialog(getActivity()); 
    // Showing progress dialog before making http request 
    pDialog.setMessage("Loading..."); 
    pDialog.show(); 



    // Creating volley request obj 
    JsonArrayRequest movieReq = new JsonArrayRequest(url, 
      new Response.Listener<JSONArray>() { 
       @Override 
       public void onResponse(JSONArray response) { 
        Log.d(TAG, response.toString()); 
        hidePDialog(); 

        // Parsing json 
        for (int i = 0; i < response.length(); i++) { 
         try { 

          JSONObject obj = response.getJSONObject(i); 
          Movie movie = new Movie(); 
          movie.setTitle(obj.getString("title")); 
          movie.setThumbnailUrl(obj.getString("image")); 
          movie.setRating(obj.getString("rating")); 
         // movie.setYear(obj.getString("releaseYear")); 
          movie.setGenre(obj.getString("genre")); 

          // Genre is json array 


          // adding movie to movies array 
          movieList.add(movie); 

         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 

        } 

        // notifying list adapter about data changes 
        // so that it renders the list view with updated data 
        adapter.notifyDataSetChanged(); 
       } 
      }, new Response.ErrorListener() { 

    @Override 
    public void onErrorResponse(VolleyError error) { 
      if (error instanceof NoConnectionError){ 
       Toast.makeText(getActivity().getBaseContext(), "Bummer..There's No Internet connection!", Toast.LENGTH_LONG).show(); 

      } 

     } 
    }); 

    // Adding request to request queue 
    AppController.getInstance().addToRequestQueue(movieReq); 

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
           int position, long id) { 

      Intent intent = new Intent(getActivity(), News_Detail.class); 

      bitmap = ((Movie)movieList.get(position)).getThumbnailUrl(); 
      intent.putExtra("images", bitmap); 

      String names = ((TextView) view.findViewById(R.id.title)).getText().toString(); 
      intent.putExtra(Title, names); 

      String genredescription = ((TextView) view.findViewById(R.id.genre)).getText().toString(); //must for send data 
      intent.putExtra(Genre, genredescription); 

      String date = ((TextView) view.findViewById(R.id.rating)).getText().toString(); 
      intent.putExtra(Rating, date); 
      startActivity(intent); 

      ImageView btn = (ImageView) view.findViewById(R.id.share); 
      btn.setOnClickListener(new AdapterView.OnClickListener(){ 

       //@Override 
       public void onClick(View v) { 
        String formattedString = android.text.Html.fromHtml(Genre).toString(); 
        Intent sendIntent = new Intent(); 
        sendIntent.setAction(Intent.ACTION_SEND); 
        sendIntent.putExtra(Intent.EXTRA_TEXT, Title + "\n" + formattedString + "\n" + " I Would like to share this with you. Here You Can Download This Application from PlayStore " + "https://play.google.com/store/apps/details?id="); 
        sendIntent.setType("text/plain"); 
        startActivity(sendIntent); 
       } 
      }); 
     } 
    }); 



    return v; 

} 





@Override 
public void onDestroy() { 
    super.onDestroy(); 
    hidePDialog(); 
} 

private void hidePDialog() { 
    if (pDialog != null) { 
     pDialog.dismiss(); 
     pDialog = null; 
    } 
} 


public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getActivity().getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

}このリンクに

クリックしてニュースdetail.java News_Detail.java

を参照するには
+0

あなたの質問を説明してください.. –

+0

私が欲しいものを記述する写真のリンクをクリックしてください? –

答えて

0

私はあなたがCustomListAdapterクラスをチェックすべきだと思います。あなたはこのようなものを持っているはずです。

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    View v = convertView; 

    if (v == null) { 
     LayoutInflater vi; 
     vi = LayoutInflater.from(getContext()); 
     v = vi.inflate(R.layout.itemlistrow, null); 
    } 

    Movie m = getItem(position); 
    TextView genre= (TextView) v.findViewById(R.id.genre); 

    *** genre.setText(m.getGenre());*** 

    return v; 
} 

スター付きラインを削除します。

+0

ありがとう、私は後で試してみよう..... –

+0

そして、OnscrollのListviewデータをもう一度やりたいと思う。私は下にスクロールして結果を表示するといくつかの結果が表示されると言っている。理解していてもいなくても。 –

+0

**インテントの作業を共有しますが、2回目以降は.on最初のクリックでNews_detailアクティビティに移動します。** ImageView btn =(ImageView)view.findViewById(R.id.share); btn.setOnClickListener(new AdapterView.OnClickListener() –

関連する問題