How to use ListView on Android tab?

Good afternoon. I have three tabs in my application (one activity is expanded by TabActivity and other actions provide access to the content). On the first tab, I have an ImageView, several TextViews and it works. But when I add a ListView and in activities that contain a ListView, I add a few lines that it did not show on the can tab.

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

In StartActivity:

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

    spec = tabHost.newTabSpec("shops").setIndicator("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 a class that extends the 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 the ListView defines (Sorry there are so many):

<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 the coffee brake, I found an error: in my xml I add the last LinearLayout "orientation = vertical" and my lines appeared. solvable

+3
1

, ListView , ScrollView. Im , :)

+2

Source: https://habr.com/ru/post/1793030/


All Articles