2016-05-12 124 views
0

我正在使用slidingtablayout。有5个选项卡,我用不同的json请求中的listview填充每个选项卡。我需要获得点击列表视图中某一项的标签的名称或标识如何获取标签名称

回答

0

您将需要向我们提供您当前的代码或实现 - 这将为我们提供关于来帮你。

但我对你实施的第一个猜测:我假设当你说SlidingTabLayout你指的是概述了Android开发者代码:https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html#l199

如果是这样的话,你可以在模板中获取的标签名称当标签被点击,并在点击监听器注册寻呼机:

private class TabClickListener implements View.OnClickListener { 
     @Override 
     public void onClick(View v) { 
      for (int i = 0; i < mTabStrip.getChildCount(); i++) { 
       if (v == mTabStrip.getChildAt(i)) { 
        mViewPager.setCurrentItem(i); 
        //Get tab name from mViewPager - differs based on your implementation 
        return; 
       } 
      } 
     } 
    } 
+0

就如何落实这 – ddnice

0

是是一个在Android开发者概述 好吧,这里的情况是

 @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的项目。我不知道为什么。 所以我想要做的就是让其中的列表视图是基于该名称的标签名称,创建JsonAdapter并获得文章

+0

就如何落实这一任何想法,任何帮助 – ddnice

+0

其确定,我在这篇文章中找到了解决方案http://stackoverflow.com/questions/7580991/how-to-make-more-than-one-listview-respond-for-different-onitemclicklistener – ddnice