开发者

How use ListView in android Tab?

开发者 https://www.devze.com 2023-02-12 02:24 出处:网络
Good day. In my app I have three tab (one Activity extend TabActivity and others activitys provides access to content). In first tab I have ImageView, a few TextView and it is works. But when I add Li

Good day. In my app I have three tab (one Activity extend TabActivity and others activitys provides access to content). In first tab I have ImageView, a few TextView and it is works. But when I add ListView and in activity that contain ListView I add a few rows it was not show in may tab.

Can someone tell me where I was wrong? Here my code:

In StartActivity:

    intent = new Intent().setClass(this, GoodsAndShopsActivity.class);

    spec = tabHost.newTabSpec("shops").set开发者_高级运维Indicator("Shops",
                      res.getDrawable(R.drawable.ic_tab_shops))
                  .setContent(intent);
    tabHost.addTab(spec);

In GoodsAndShopsActivity:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.descriptions);

    m_shopsLayout = (ListView) findViewById(R.id.shops);

    m_shopList = new ArrayList<Shop>();
    m_shopAdapter = new ShopAdapter(m_shopList, this);
    m_shopsLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    m_shopsLayout.setAdapter(m_shopAdapter);

    for (int i = 0; i<3; i++) {
        m_shopList.add(new Shop("new description"));
        m_shopAdapter.notifyDataSetChanged();
    }

}

In class that extends BaseAdapter:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = m_inflater.inflate(R.layout.shop, null);

        holder = new ViewHolder();
        holder.descriptions = (TextView) convertView.findViewById(R.id.shop);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    String textOnView = m_shops.get(position).getDescription();
    holder.descriptions.setText(textOnView);
    return convertView;
}

static class ViewHolder{
    TextView descriptions;
}

And my xml where define ListView (Sorry that so much):

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

<LinearLayout
    android:id="@+id/full_info"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

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

        android:layout_margin="10px"
        android:src="@drawable/icon">
    </ImageView>

    <LinearLayout
        android:id="@+id/short_info"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/icon"
        android:layout_alignParentRight="true">

        <TextView
            android:id="@+id/name_for_good"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="Наименование товара">
        </TextView>

        <TextView
            android:id="@+id/best_price"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" 

            android:singleLine="true"
            android:ellipsize="marquee"
            android:text="Лучшая цена: ">
        </TextView>

        <TextView
            android:id="@+id/worst_price"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:text="Худшая цена: ">
        </TextView>

    </LinearLayout>
</LinearLayout>
<LinearLayout
    android:id="@+id/description_and_shop"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/full_info">

    <TextView
        android:id="@+id/description"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Большое подробное описание товара с всякими деталями, нюансами и т.п.">
    </TextView>    

    <ScrollView
        android:id="@+id/ScrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ListView
            android:id="@+id/shops"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
        </ListView>
    </ScrollView>

</LinearLayout>

UPDATE: After coffe brake I was find mistake: in my xml I add in last LinearLayout "orientation=vertical" and my rows appeared. SOLVED


Also, remember that the ListView is already scrollable, so you shouldn't need to put it under ScrollView. Im glad you solved your problem youself :)

0

精彩评论

暂无评论...
验证码 换一张
取 消