首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android中的Galleryview

android中的Galleryview
EN

Stack Overflow用户
提问于 2012-12-07 13:56:32
回答 1查看 249关注 0票数 0

您好,我对这个android..Actually非常陌生,我正在尝试在屏幕上显示它下面的1个标题和描述。我已经使用Galleryview.I做到了这一点。我不知道这样做是否正确。

我的实际想法is..In galleryview如果我滑动屏幕下一个(标题和描述应该会出现),但我不能做this..SO我试图保留下一个和上一个选项来做this..But这也我不能..I知道我正在做错误的way.Please建议我一些好的方式来做这件事。如果下面发布的needed..The代码是我所做的,我准备给出更多的解释。

我的活动代码:

代码语言:javascript
复制
public class NewsDescription extends Activity
{
//   private String url = "http://m.indiatoday.in/xml/stories/"+(String)context.getInstance().getAppVariable("storyurl");
     public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.newsdesgallery);            
 Gallery gl=(Gallery)findViewById(R.id.GalleryNewsDesc);
            NewsDescriptionAdapter adapter =new NewsDescriptionAdapter(this);
            gl.setAdapter(adapter);   
}
}

我的适配器类:

代码语言:javascript
复制
public class NewsDescriptionAdapter extends  BaseAdapter
{
    private static Context contxt;


    String[] body= {};//new String[30];
    String[] heading= {};//new String[30];
    NewsDescriptionAdapter(Context conxt)
    {
//      System.out.println("inside cons");
        this.contxt=conxt;
        getelement();
    }

    public void getelement()
    {
//      System.out.println("Inside getElement");
        String[] url=context.getInstance().getselectedUrl();
//      System.out.println("After url");
//      System.out.println("count="+(String)context.getInstance().getAppVariable("count"));
        int count = Integer.parseInt((String)context.getInstance().getAppVariable("count"));
//      System.out.println("count="+count);
//      System.out.println("after count="+url[count]);
        String URL = "http://xxxx.in/xml/stories/"+url[count];  
//      System.out.println("url="+URL);
         TaplistingParser parser = new TaplistingParser();
//          try {
//              url=URLEncoder.encode(url, "UTF-8");
//          } catch (UnsupportedEncodingException e1) {
//              // TODO Auto-generated catch block
//              e1.printStackTrace();
//          }
            URL=URL.replace(" ","");
//          System.out.println("url="+url);
            String xml= parser.getXmlFromUrl(URL);
            Document doc=parser.getDomElement(xml);                 
            NodeList n1 = doc.getElementsByTagName("item");
            body = new String[n1.getLength()];
            heading = new String[n1.getLength()];
            for( int i = 0 ; i < n1.getLength(); i++ )
            {
//              HashMap<String, String> map = new HashMap<String, String>();
                Element e = (Element) n1.item(i);
                body[i]=parser.getValue(e, "body");
                heading[i]=parser.getValue(e, "headline");
//              map.put("Body", parser.getValue(e,"body"));             
//              menuItems.add(map);
            }
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return body.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return body[position];
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        // TODO Auto-generated method stub
//      System.out.println("body="+body[position]);
         if (convertView   == null) 
            {
                //this should only ever run if you do not get a view back            
             LayoutInflater  inflater = (LayoutInflater) contxt
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             convertView  = inflater.inflate(R.layout.newsdescriptionrow, null); 
            }        
         TextView next =(TextView)convertView.findViewById(R.id.nextnews);
//       final Gallery gal=(Gallery)convertView.findViewById(R.id.GalleryNewsDesc);

         next.setOnClickListener(new View.OnClickListener() 
         {          
            @Override
            public void onClick(View arg0) 
            {
                // TODO Auto-generated method stub
                System.out.println("Inside next");
                int count = Integer.parseInt((String)context.getInstance().getAppVariable("count"));
                count++;
                context.getInstance().setAppVariable("count", Integer.toString(count));     


            }
        });     

         TextView textViewhead = (TextView) convertView
                    .findViewById(R.id.name_DescHeading);
         textViewhead.setText(heading[position]);

             TextView textView = (TextView) convertView
                    .findViewById(R.id.name_Desclabel);
            textView.setText(body[position]);
        return convertView;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2012-12-07 14:34:41

你不应该再使用图库小工具了,因为在新版本的安卓中,它是不推荐使用的。相反,你可以使用android support jar中的ViewPager。

你可以在这里找到一个例子:https://github.com/nostra13/Android-Universal-Image-Loader

在上面的代码中查找ImagePagerActivity。您可以创建一个带有图像视图和文本视图的自定义单元格用于描述(修改item_pager_image xml)。让我知道进展如何。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13757696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档