2012-07-11 25 views
0

我有這樣的佈局選項卡應用:適配器訥韋爾進入getView方法

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/tabhost" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="3dp"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom = "@android:id/tabcontent" 
      /> 
    </RelativeLayout> 
</TabHost> 

我想打電話給一個ListView屏幕,所以我這樣設計:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

和gridview的樣子

<?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" android:background="#ffffff"> 

    <ImageView 
     android:id="@+id/imageViewContent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     /> 

     <TextView 
     android:id="@+id/textViewCategoryName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:paddingLeft="8dip" 
     /> 

</LinearLayout> 

,我打電話使用適配器:

SectionsAdapter adapter = new SectionsAdapter(Sections.this ,R.layout.sectionviewgridview, 
          appState.MainCategories); 
        // updating listview 
        setListAdapter(adapter); 

和適配器的樣子:

public class SectionsAdapter extends ArrayAdapter<HashMap<String, String>>{ 

    ArrayList<HashMap<String, String>> mainCategories; 

    private final Context context; 

    public SectionsAdapter(Context context, int ResourceId, 
      ArrayList<HashMap<String, String>> items) 
    { 
     super(context, ResourceId); 
     this.context = context; 
     this.mainCategories = items ; 

     Log.d("The count of the hash is",""+items.size()); 

    } 

    @Override 
public View getView(int position, View convertView, ViewGroup parent) 

{ 

     Log.d("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx","I'm hereeeeeeeeeeeeeeeeeeeeeeeeee"); 


     LayoutInflater inflater = (LayoutInflater) context 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     View rowView = inflater.inflate(R.layout.sectionviewgridview, parent, false); 

     ImageView ImageViewObject = (ImageView)rowView.findViewById(R.id.imageViewContent); 



     try { 
       Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new java.net.URL(mainCategories.get(position).get("imageUrl")).getContent()); 
       ImageViewObject.setImageBitmap(bitmap); 

      } catch (MalformedURLException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

     Log.d(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",mainCategories.get(position).get("name")); 

     TextView TextViewObject = (TextView) rowView.findViewById(R.id.textViewCategoryName); 

     TextViewObject.setText(mainCategories.get(position).get("name")); 

     return rowView; 




} 

} 

它從來沒有記錄什麼的getView方法。任何想法如何解決這個問題?

回答

2

如果您的ArrayAdapter分機回用super(context, ResourceId);超類,那麼你必須確保覆蓋getCount方法返回確切的數據大小,否則,該適配器將不知道你要使用的mainCategories作爲下劃線數據並將創建一個List大小爲0getView方法將不會被調用。我不知道究竟你打算如何使用ArrayListMaps這一點,但嘗試添加到您的SectionedAdapter

@Override 
public int getCount() { 
    return mainCategories.size(); 
} 

如果這不能解決問題再加入約你在做什麼的更多細節。

0

我有同樣的問題..

我的佈局:在RelativeLayout的和ListView的內容來定義

的ListView是一個更RelativeLayout的定義了兩個textviews。

問題:

兩個textviews寬度被提及了作爲0dp,因爲這個getview的位置爲0,沒有顯示的內容。

解決:

解決通過提供兩個textviews的寬度爲wrap_content。

相關問題