【发布时间】:2015-02-02 22:26:00
【问题描述】:
我遇到的每个示例/教程都只是将字符串添加到 ListViews,但我想添加膨胀视图。我已经测试了膨胀的视图,如果我使用 addView() 将它添加到某个 ViewGroup(如 RelativeLayout)中,它看起来很好。但是将膨胀的视图添加到 ListView 只是以文本的形式显示它:
ArrayList<View> friend_request_items = new ArrayList<View>(); //a list containing the items we want to add
ListView friend_request_list = (ListView) findViewById( R.id.friend_request_list );
ArrayAdapter<View> friend_request_adapter = new ArrayAdapter<View>( this, android.R.layout.simple_list_item_1, friend_request_items);
friend_request_list.setAdapter( friend_request_adapter );
//friend_template is just my own xml file containing the view I'm inflating
View friend_request_item = LayoutInflater.from(this).inflate(R.layout.friend_template, null);
friend_request_items.add( friend_request_item );
friend_request_adapter.notifyDataSetChanged();
我认为问题在于我传递给适配器的布局,但我不知道将其更改为什么(或者这甚至是解决方案)。
【问题讨论】:
标签: android listview android-listview