2016-05-11 23 views
0

私は、別のJsonリクエストでslidingTabLayoutを持っています。 これまで、私はそれぞれのpage_adapterごとに異なるクエリに基づいて異なるリクエストを得ることができました。 今私がしたいことは、アイテムをクリックするとarticle_layoutに送られますが、問題は私がonItemClickをどのように設定するのか分からないことです。ここonItemClick ListView、別のアダプタ

はjsonObjectのみhomeJSONAdapterに設定されているJSONObject jsonObject = (JSONObject) homeJSONAdapter.getItem(position);ラインにおけるonItemClick

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

      JSONObject jsonObject = (JSONObject) homeJSONAdapter.getItem(position); 
      String imageURL = jsonObject.optString("image_url"); 
      String Text1 = jsonObject.optJSONObject("content").optString("rendered"); 
      String text2 = jsonObject.optJSONObject("title").optString("rendered"); 


      Intent detailIntent = new Intent(getActivity(), SingleArticle.class); 


      detailIntent.putExtra("imgURL", imageURL); 
      detailIntent.putExtra("articleText", Text1); 
      detailIntent.putExtra("articleTitle", Text2); 

      startActivity(detailIntent); 

     } 

するためのコードです。どのような私が欲しいのかに基づいて様々なアダプタを持っているユーザーを表示するので、そのリストの記事

答えて

0
@Override 
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

     ...... 
     ...... 

     if(position ==1) 
     { 


     Intent detailIntent = new Intent(getActivity(), SingleArticle.class); 


     detailIntent.putExtra("imgURL", imageURL); 
     detailIntent.putExtra("articleText", Text1); 
     detailIntent.putExtra("articleTitle", Text2); 

     startActivity(detailIntent); 

    } 

     if(position ==2) 
     { 

      //start another activity 
     Intent detailIntent1 = new Intent(getActivity(), SingleArticle1.class); 


     detailIntent1.putExtra("imgURL1", imageURL); 
     detailIntent1.putExtra("articleText1", Text1); 
     detailIntent1.putExtra("articleTitle1", Text1); 

     startActivity(detailIntent1); 

    } 

     if(position ==3) 
     { 

      //start another activity 
     Intent detailIntent2 = new Intent(getActivity(), SingleArticle2.class); 


     detailIntent2.putExtra("imgURL2", imageURL); 
     detailIntent2.putExtra("articleText2", Text2); 
     detailIntent2.putExtra("articleTitle2", Text2); 

     startActivity(detailIntent2); 

    } 

    ..... 
    ..... 
    so on 

    } 
+0

ポジションは、リストアイテムの位置を取得します。私は何のアイデアを持っているかを確認するために何か必要があると思いますか? – ddnice

0

[OK]を読み取るために、ここではそれがない基本的に、すべての状況

 @Override 
      public Object instantiateItem(ViewGroup container, int position) { 

       View view=null; 
       if(position == 0){ 
        view = getActivity().getLayoutInflater().inflate(R.layout.pager_item,container, false); 
        homeList = (ListView) view.findViewById(R.id.home_list); 
        queryImp(view, ""); 
        homeJSONAdapter = new JSONAdapter(getActivity(), getActivity().getLayoutInflater()); 

        homeList.setAdapter(homeJSONAdapter); 
        homeList.setOnItemClickListener(this); 


       }else{ 
        view = getActivity().getLayoutInflater().inflate(R.layout.other_pager_item,container, false); 
        otherList = (ListView) view.findViewById(R.id.other_list); 
        queryImp(view, "other"); 
        otherJSONAdapter = new JSONAdapterOther(getActivity(), getActivity().getLayoutInflater()); 

        otherList.setAdapter(ekonomiaJSONAdapter); 
        otherList.setOnItemClickListener(this); 

       } 

       container.addView(view); 

       view.findViewById(R.id.item_title); 

       return view; 
      } 

this is the code that populates the tabs on SlidingTabsBasicFragment and the following is the onclick for the items of the lists 

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


      if(position == 0) 
      { 

       JSONObject jsonObject = (JSONObject) homeJSONAdapter.getItem(position); 
       String imageURL = jsonObject.optString("img_url"); 
       String artText = jsonObject.optJSONObject("content").optString("rendered"); 
       String artTitle = jsonObject.optJSONObject("title").optString("rendered"); 


       Intent detailIntent = new Intent(getActivity(), SingleArticle.class); 


       detailIntent.putExtra("imgURL", imageURL); 
       detailIntent.putExtra("articleText", artText); 
       detailIntent.putExtra("articleTitle", artTitle); 

       startActivity(detailIntent); 

      }else{ 


       JSONObject jsonObject1 = (JSONObject) otherJSONAdapter.getItem(position); 
       String imageURL1 = jsonObject1.optString("img_url"); 
       String artText1 = jsonObject1.optJSONObject("content").optString("rendered"); 
       String artTitle1 = jsonObject1.optJSONObject("title").optString("rendered"); 

       y 
       Intent detailIntent1 = new Intent(getActivity(), SingleArticleOther.class); 


       detailIntent1.putExtra("imgURL1", imageURL1); 
       detailIntent1.putExtra("articleText1", artText1); 
       detailIntent1.putExtra("articleTitle1", artTitle1); 


       startActivity(detailIntent1); 

      } 

があるさリストの項目をクリックすると、完全な記事が読み込まれます。何らかの理由ですべてが混乱する。私がhomeJsonAdapterの項目をクリックしようとすると、otherJsonAdapterの記事に行きます。どうしてか分かりません?

関連する問題