我有以下布局: 黄色背景是列表项,存储在片段中。
这是我 mainActivity 的代码:
<fragment android:layout_width="140dp"
android:layout_height="100dp"
android:layout_below="@+id/block"
class="fragments.Demo"/>
片段代码:
public class Demo extends ListFragment{
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity().getApplicationContext(), R.layout.list_item_bank, R.id.list_item_bank_name, values);
setListAdapter(adapter);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.transaction_list_fragment, null);
}
}
R.layout.list_item_bank:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffee00"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView android:id="@+id/list_item_bank_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:text=""
android:textColor="@color/abs__primary_text_holo_light"
android:textSize="18sp">
</TextView>
</LinearLayout>
问题是:我无法从主要活动滚动列表视图。怎么了?