2011-12-08 1 views
0

갤러리를 만들었으므로 이제 코드에서 변경하고 싶습니다. 갤러리의 요소는 두 으로 구성되어 있으며 줄 수를 얻고 싶습니다.갤러리 요소 가져 오기

내가 시도 :

TextView top = (TextView)findViewById(R.id.top); 
top.getLineCount(); 

그러나 응용 프로그램은 누군가가 생각이 있습니까 top.getLineCount();에 추락? CustomAdapter

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

     LayoutInflater iteminflater = LayoutInflater.from(mContext); 
     View gallaryitem = iteminflater.inflate(R.layout.gallery_item, null); 
     ImageView imgView= (ImageView) gallaryitem .findViewById(R.id.item); 
     imgView.setImageResource(mImageIds[position]); 


     //TextView top = (TextView)convertView.findViewById(R.id.top); 
     //top.getLineCount(); 





     return gallaryitem ; 
    } 

LayoutFile

<?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="wrap_content" 
      android:padding="10px" > 

    <ImageView 
    android:id="@+id/item" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:src="@drawable/icon" 
    android:gravity="center" 
    android:background="#4E4E4E"/> 


<TextView 
    android:id="@+id/bottom" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="moremore" 
    android:textSize="27sp" 

    android:layout_marginTop="275dip" 
    android:paddingTop="35dip" 
    android:textColor="#eeeeee" 
    android:background="#60000000" 
    android:textStyle="bold" 
    android:typeface="sans"/> 

<TextView 
    android:id="@+id/top" 
    android:layout_width="fill_parent" 
    android:text="testtesttesttesttesttesttest" 
    android:textSize="22sp" 
    android:layout_marginTop="280dip" 
    android:layout_marginLeft="10dip" 
    android:layout_marginRight="10dip" 
    android:textColor="#eeeeee" 
    android:background="#60ff0000" 
    android:textStyle="bold" 
    android:typeface="sans" 
    android:layout_height="wrap_content"/> 

</RelativeLayout> 
+0

당신이 당신의 갤러리에서 코드의 텍스트 뷰 라인 퍼팅을 ?? –

+0

CustomAdapter 및 Layoutfile을 추가합니다. –

+0

오류가 발생했을 때의 오류는 무엇입니까 –

답변

0

의 getView 당신은 갤러리의 아이들을 수정하기위한 사용자 정의 어댑터를해야한다. 갤러리에

class MyAdapter extends ArrayAdapter<E>{ 
     public MyAdapter(Context context, int textViewResourceId, E[] objects) { 
      super(context, textViewResourceId, objects); 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      if(convertView== null) convertView = getLayoutInflater().inflate(R.layout.your_layout, null); 

      //Modify contents of your gallery here.. example: 
      TextView top = (TextView)convertView.findViewById(R.id.top); 
      top.getLineCount(); 

      return convertView; 
     } 
    } 

설정 그것은 당신이 정상적인 어댑터 설정 방법 :

myGallery.setAdapter(new MyAdapter(...)); 
+0

이 두 줄의 코드를 내 customadapter에 추가하면 응용 프로그램이 다운됩니다 ... 이유는 무엇입니까? –

+0

갤러리에 채울 레이아웃에 TextView가 있습니까? 뷰를 찾을 수없는 경우 null의 lineCount를 얻으려고합니다. – Jave

+0

CustomAdapter 및 Layoutfile을 추가합니다. –