美好的一天。 在我的应用程序中,我有三个选项卡(一个Activity扩展TabActivity,其他活动提供对内容的访问)。在第一个选项卡中,我有ImageView,一些TextView,它是有效的。但是当我添加ListView并且在包含ListView的活动中,我添加了几行,它们在may标签中没有显示。
有人可以告诉我哪里错了吗?这是我的代码:
在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);
在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();
}
}
在扩展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;
}
我的xml定义了ListView(很抱歉这么多):
<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>
更新:在咖啡制动后我发现错误:在我的xml中我添加了最后一个LinearLayout“orientation = vertical”并且我的行出现了。 的解决
答案 0 :(得分:2)
此外,请记住ListView
已经可滚动,因此您不需要将其置于ScrollView
之下。
我很高兴你自己解决了问题:)