2012-12-07 21 views
0

嗨,我是很新的這android..Actually我試圖在screen.I顯示1個標題和描述它下面已經做了使用Galleryview.I不知道這是否是正確的方式來做這個R值不要..在圖庫視圖的Android

我其實想法is..In如果圖庫視圖我輕掃屏幕的下一個(標題和描述應來),但我不能這樣做this..SO我試圖保持一個和前一個選項做到這一點..但這也不能做..我知道我在做錯誤的方式。請建議我一些好處做到這一點..我準備好給更多的解釋,如果需要..下面貼的代碼是什麼我完成了...

我的活動代碼:

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); 
} 
} 

我的適配器類:

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; 
    } 
} 

回答

0

你不應該使用庫部件更多,因爲它是在的Android新版本棄用。相反,您可以使用Android支持jar中的ViewPager。

你可以在這裏找到一個例子:在上面的代碼 https://github.com/nostra13/Android-Universal-Image-Loader

山的ImagePagerActivity。您可以創建與描述的ImageView的和TextView的自定義單元格(修改item_pager_image XML)。讓我知道事情的後續。