【发布时间】:2015-07-19 01:02:08
【问题描述】:
我有一个现有的片段,我想在其中显示典型的地址类型的信息,例如街道、城市、PIN 和电话号码列表。
为了显示电话号码列表,我在 addressfragment.xml 中添加了列表视图:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp" >
<TextView
android:id="@+id/txtStreetAddr"
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.2"
android:text="default" />
<ListView
android:id="@+id/phones"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:paddingLeft="0dp" >
</ListView>
</LinearLayout>
</ScrollView>
我的片段类:
public class AddressFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater
.inflate(R.layout.fragment_screen_slide_page, container, false);
((TextView) rootView.findViewById(R.id.txtStreetAddr)).setText(
"123, Corner Street");
ListView phoneListView = ((ListView) rootView.findViewById(R.id.phones));
ArrayList<String> phNumbers = new ArrayList<String>();
phNumbers.add("4343534343");
phNumbers.add("6767566766");
ArrayAdapter<String> arrayAdapter =
new ArrayAdapter<String>(MyApp.getAppContext(),android.R.layout.simple_list_item_1, phNumbers);
// Set The Adapter
phoneListView.setAdapter(arrayAdapter);
return rootView;
}
电话列表视图只是没有显示在屏幕上 - 为什么? 有没有更好的方法来处理这个问题?
【问题讨论】:
-
完全发布你的布局xml文件
-
并发布完整的 onCreateView。发布完整的布局
标签: android android-listview android-listfragment