1
這是一個包含listview的片段代碼。但它沒有顯示任何東西。這個片段與一個選項卡有關。這個標籤視圖包含三個片段,這一個沒有顯示。爲什麼? 我添加了該片段的代碼以及相關的xml和其他類代碼。片段不顯示任何內容
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();
}
}
fragmentmovie:
<?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>
mainlist:
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;
}}
maintemp
<?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="match_parent"
android:orientation="horizontal" android:visibility="visible">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_margin="5dip"
android:background="@drawable/shape1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" android:padding="5dip" android:gravity="center" android:textSize="18dip" android:textColor="#ffffff"/>
電影片段 – AndroidHacker
感謝您返回錯誤類型的內容。是的,它返回錯誤的類型。 – user5508330
歡迎你 – AndroidHacker