2012-11-22 5 views
0

내 응용 프로그램에서 올바르게 갤러리 이미지를 표시하기 위해 갤러리를 5 개 사용하고 있습니다. 이미지를 올바르게 채울 수 있습니다. 이제 각 이미지 아래에 textview를 추가하고 싶습니다.갤러리 뷰의 각 이미지 아래에 Textview

image1 Image2 Image3 image4 
              -------->Galleryview1 

text1  text2  text3 text4 

------------------------------------------ 
image1 image2 image3 image4 

              --------->Galleryview2 
text1  text2  text3 text4 

내 코드 :

어댑터 코드 :

public class GalleryviewAdapter extends BaseAdapter 
{  

    static final String URL="http://aaaa/home.xml"; 


    public static GalleryviewAdapter instance=new GalleryviewAdapter(); 
    public static GalleryviewAdapter getInstance() 
     { 
      return instance; 
     } 
     Context context;   
     GalleryviewAdapter() 
     { 
      System.out.println("Inside cons"); 
      getelement(); 
//   getelementindia(); 
     } 
//  String[] itemsArray = 
//   { 
//  "SUN","MON", "TUS", "WED", "THU", "FRI", "SAT" 
//   }; 

//  MyAdapter(Context c) 
//  { 
//  context = c; 
//  } 

     private Activity activity; 
     private LayoutInflater inflater=null; 
     public void ImageAdapter(Activity a) 
     { 
      activity = a; 
       inflater = (LayoutInflater)activity.getSystemService 
         (Context.LAYOUT_INFLATER_SERVICE);   
     } 

    String imageurl[]= {};//new String[5]; 
// String imageurlindia[]={}; 
    public void getelement() 
    { 
     System.out.println("Inside getelement"); 
//  String[] itemsarray={}; 
//  ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); 
//  ArrayList<String> menuItems = new ArrayList<String>(); 
     TaplistingParser parser = new TaplistingParser(); 
     String xml= parser.getXmlFromUrl(URL); 
     Document doc=parser.getDomElement(xml);   
//  System.out.println("sssss="+doc); 
     NodeList nl=doc.getElementsByTagName("article"); 
     imageurl = new String[nl.getLength()]; 
     System.out.println("len="+nl.getLength()); 
     for(int i=0; i < nl.getLength(); i++) 
     { 
//   System.out.println("Inside for"); 
//   HashMap<String, String> map = new HashMap<String, String>(); 
     Element e = (Element) nl.item(i); 
//   map.put("SectionName", parser.getValue(e, "sectionname")); 
//   System.out.println("b4 items="+parser.getValue(e, "sectionname")); 
//   itemsarray[i] = parser.getValue(e, "sectionname"); 
//   System.out.println("items="+itemsarray[i]); 
     imageurl[i]=parser.getValue(e, "kickerimage"); 
//   menuItems.add(parser.getValue(e, "sectionname")); 
//  menuItems.add(parser.getValue(e, "sectionname")); 
//  System.out.println("menu="+menuItems); 

     }  
//  String[] itemsarray = menuItems.toArray(new String[menuItems.size()]); 

//  String[] itemsarray = new String[menuItems.size()]; 
//  itemsarray=menuItems.toArray(itemsarray); 
////  for(int j= 0;j < itemsarray.length;j++) 
////  { 
////   Log.d("string is",(itemsarray[j])); 
////  } 
//  return itemsarray; 
    } 





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


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


     public long getItemId(int position) 
     { 

     return position; 
     } 

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

//  System.out.println("sssssssss="+imageurl[position]); 
//   View vi=convertView; 
//   ViewHolder holder; 
//   if(convertView==null) 
//   { 
//    vi = inflater.inflate(R.layout.main, null); 
//    holder=new ViewHolder(); 
//    holder.text=(TextView)vi.findViewById(R.id.Txt01); 
//    holder.image=(ImageView)vi.findViewById(R.id.imageview1); 
//    vi.setTag(holder); 
//   } 

     Bitmap bitmap=DownloadImage(imageurl[position]); 
     View rowView = LayoutInflater 
     .from(parent.getContext()) 
     .inflate(R.layout.main, null); 
//  
     ImageView imgview=(ImageView)rowView.findViewById(R.id.imageview1);  
     imgview.setImageBitmap(bitmap); 


//  
//  ImageView imgviewindia=(ImageView)rowView.findViewById(R.id.imageviewindia); 
//  imgviewindia.setImageBitmap(bitmap); 


//  TextView listTextView = (TextView)rowView.findViewById(R.id.); 
//  listTextView.setText(getelement()[position]);   
     return rowView; 
     } 

     private Bitmap DownloadImage(String URL) 
     {   
//   System.out.println("image inside="+URL); 
      Bitmap bitmap = null; 
      InputStream in = null;   
      try 
      { 
       in = OpenHttpConnection(URL); 
       bitmap = BitmapFactory.decodeStream(in); 
       in.close(); 
      } catch (IOException e1) { 
       // TODO Auto-generated catch block 
       e1.printStackTrace(); 
      } 
//   System.out.println("image last"); 
      return bitmap;     
     } 
     private InputStream OpenHttpConnection(String urlString) 
       throws IOException 
       { 
        InputStream in = null; 
        int response = -1; 

        URL url = new URL(urlString); 
        URLConnection conn = url.openConnection(); 

        if (!(conn instanceof HttpURLConnection))      
         throw new IOException("Not an HTTP connection");     
        try{ 
         HttpURLConnection httpConn = (HttpURLConnection) conn; 
         httpConn.setAllowUserInteraction(false); 
         httpConn.setInstanceFollowRedirects(true); 
         httpConn.setRequestMethod("GET"); 
         httpConn.connect(); 

         response = httpConn.getResponseCode();     
         if (response == HttpURLConnection.HTTP_OK) 
         { 
          in = httpConn.getInputStream();         
         }      
        } 
        catch (Exception ex) 
        { 
         throw new IOException("Error connecting");    
        } 
        return in;  
     } 
     } 
// } 

main.xml에 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <ImageView 
     android:id="@+id/imageview1" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="-20dp" 
     android:layout_width="120dp" 
     android:layout_height="100dp"   
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     /> 
     <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/Txt01" /> 

</LinearLayout> 

는이 같은 갤러리보기를 원하는 510,403,210 내 주요 activitycode :

public class NewspapperActivity extends Activity 
{ 
    /** Called when the activity is first created. */ 
    Context ctx; 

    static final String URLHeading = "http://aaaaaa.in/cccccc.xml"; 
    String[] headingurl=new String[20]; 
// ListViewwithimageAdapter adapter; 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.galleryview);   
//  ArrayList<String>item = new ArrayList<String>(); 

     Heading parser = new Heading();  
     String xmldata = parser.getXmlFromUrl(URLHeading); 

     Document domelement = parser.getDomElement(xmldata); 

     NodeList node = domelement.getElementsByTagName("item"); 

//  int i ; 

     TextView txt1 = (TextView)findViewById(R.id.Text01); 
     TextView txt2 = (TextView)findViewById(R.id.Text02); 
     TextView txt3 = (TextView)findViewById(R.id.Text03); 
     TextView txt4 = (TextView)findViewById(R.id.Text04); 
     TextView txt5 = (TextView)findViewById(R.id.Text05); 


//  glly.setAdapter(adapter); 
//  System.out.println("prakash4"); 
//  for(i=0 ; i < node.getLength();i++) 
//  { 
      Element e0 = (Element) node.item(0); 
      txt1.setText(parser.getValue(e0, "sectionname")); 

      Element e1 = (Element) node.item(1); 
      txt2.setText(parser.getValue(e1, "sectionname")); 

      Element e2 = (Element) node.item(2); 
      txt3.setText(parser.getValue(e2, "sectionname")); 

      Element e3 = (Element) node.item(3); 
      txt4.setText(parser.getValue(e3, "sectionname")); 

      Element e4 = (Element) node.item(4); 
      txt5.setText(parser.getValue(e4, "sectionname")); 

      Gallery glly= (Gallery)findViewById(R.id.Gallery01); 
      Gallery glly2= (Gallery)findViewById(R.id.Gallery02); 
      Gallery glly3= (Gallery)findViewById(R.id.Gallery03); 
      Gallery glly4= (Gallery)findViewById(R.id.Gallery04); 
      Gallery glly5= (Gallery)findViewById(R.id.Gallery05); 
//   GridView gv = (GridView)findViewById(R.id.grid); 

//   ListViewwithimageAdapter adapter = ListViewwithimageAdapter.getInstance(); 
      GalleryviewAdapter adapter=GalleryviewAdapter.getInstance(); 
      glly.setAdapter(adapter);  
      glly.setSelection(1); 
      glly2.setAdapter(adapter); 
      glly2.setSelection(1); 
      glly3.setAdapter(adapter); 
      glly3.setSelection(1); 
      glly4.setAdapter(adapter); 
      glly4.setSelection(1); 
      glly5.setAdapter(adapter); 
      glly5.setSelection(1); 
//   item.add(parser.getValue(e, "sectionname")); 
//  } 
//  gv.setAdapter(new GridviewImageAdapter(this)); 

    } 

}

내가 사전에이 ..Please 도움이 와요 고마워요 새로운 오전 .. 대신 XML 코드의 XML 코드 아래

답변

0

사용, 그것은 해결됩니다 당신의 문제 그리고 그 문제에 관해서는 저에게 말하십시오.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/imageview1" 
      android:layout_width="120dp" 
      android:layout_height="100dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="-20dp" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:src="@drawable/ic_launcher"/> 

     <TextView 
      android:id="@+id/Txt01" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/imageview1" 
      android:layout_centerHorizontal="true" 
      android:text="Dipak" /> 
    </RelativeLayout> 

</RelativeLayout> 
+0

덕분에 이미지가 텍스트가 그래서 난 문제가 어디 이해할 수 .. – Subburaj

+0

@Subburaj 게시 완전한 자바와 XML 코드를 보여주고있다 coming..only되지 않습니다 IGP..But? –

+0

IGP .. 내 전체 코드를 게시했습니다. 내 편집 된 게시물을 참조하십시오. – Subburaj