这是包含listview的片段代码。但它没有显示任何东西。此片段与选项卡相关。此选项卡视图包含三个片段,这一个没有显示。为什么? 我添加了该片段的代码以及相关的xml和其他类代码。
def NextDataSet():
for eachDataSet in BigList:
graphData(eachDataSet)
fragmentmovie:
public class MoviesFragment extends Fragment {
String[] numbers_text = new String[] { "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten", "eleven",
"twelve", "thirteen", "fourteen", "fifteen" };
String[] numbers_digits = new String[] { "1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15" };
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_movies, container, false);
MainCustomList adapter = new MainCustomList(this.getActivity(), numbers_text, numbers_digits);
ListView list;
list=(ListView) view.findViewById(R.id.list);
list.setAdapter(adapter);
return getView();
}
}
mainlist:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#17df0d"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" >
</ListView>
</RelativeLayout>
maintemp
public class MainCustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] str1;
private final String[] str2;
public MainCustomList(Activity context,String[] str1, String[] str2) {
super(context, R.layout.maintemp, str1);
this.context = context;
this.str1 = str1;
this.str2 = str2;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.maintemp, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.textView1);
TextView txtTitle2 = (TextView) rowView.findViewById(R.id.textView2);
txtTitle.setText(str1[position]);
txtTitle2.setText(str2[position]);
return rowView;
}}
答案 0 :(得分:1)
return getView();
错了。片段getView返回onCreateView
的结果,null
返回onCreateView
之前的return getView();
。你会回来null。改变
return view;
带
{{1}}
您充气的视图,其中包含您要显示的内容