0

次のようなレイアウトのタブアプリケーションがあります。

<?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>

グリッドビューは次のようになります

<?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。それを修正する方法はありますか?

4

2 に答える 2

2

ArrayAdapterでスーパークラスにコールバックする拡張機能がある場合super(context, ResourceId);は、メソッドをオーバーライドしgetCountて正確なデータサイズを返すようにする必要があります。そうしないと、アダプターはmainCategories、を下線付きデータとして使用することを認識せず、を作成しますList。サイズ0getViewメソッドは呼び出されません。ArrayList私はあなたがそれをどのように使用する予定か正確にはわかりませんが、これをあなたの:Mapsに追加してみてくださいSectionedAdapter

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

これで問題が解決しない場合は、何をしているかについての詳細を追加してください。

于 2012-07-12T02:48:57.903 に答える
0

私は同じ問題を抱えていました。

私のレイアウト:

Relativelayoutで定義されたListViewとlistviewのコンテンツは、もう1つのRelativelayoutで定義された2つのテキストビューです。

問題:

2つのテキストビューの幅は0dpと記載されていました。これは、getviewの位置が0であり、コンテンツが表示されていないためです。

解決済み:

wrap_contentに2つのテキストビューの幅を提供することで解決しました。

于 2014-03-19T15:17:24.587 に答える