你好,我是在填充上片段 以下列表视图有问题是我的fragment.class移植ListView在片段
package com.example.fred.p;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
/**
* A simple {@link Fragment} subclass.
*/
public class MainFragment extends Fragment {
public MainFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String[] game = { "Android", "iOS", "window" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView(), getContext() , android.R.layout.p_g, game);
getListView(), setAdapter(adapter);
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_main, container, false);
}
}
碎片的xml文件如下。我想填充只有三个 项目的视图可以有人请帮助我这是我写的代码 谢谢。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.fred.p.MainFragment">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:rowCount="2"
android:columnCount="1"
android:orientation="vertical"
android:id="@+id/home"
android:paddingBottom="8dp">
<ImageView
android:id="@+id/pd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/p_adds"
android:scaleType="centerCrop"/>
</GridLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView
android:id="@+id/p_g"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
</ListView>
</LinearLayout>
</LinearLayout>
发布堆栈跟踪或有任何编译错误 – DJphy
错误是它无法找到getListView和p_g(这是xml文件中的列表视图的ID)@DJphy – user3551487
创建方法getListView() – DJphy