Tôi biết rằng đã có câu hỏi simialr nhưng tôi không thể làm cho nó hoạt động ngay cả khi tôi nhìn vào . Các thông báo lỗi là:java.lang.RuntimeException: Nội dung của bạn phải có một ListView có thuộc tính id là 'android.R.id.list'
java.lang.RuntimeException: Nội dung của bạn phải có một ListView có id thuộc tính là 'android.R.id.list'
. Tôi đã cố gắng thay đổi id thành danh sách. Trong cái khác. Đây gì mã trông giống như:
public class committeeFragment extends SherlockListFragment {
private CommitteeAdapter adapter;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new CommitteeAdapter(getActivity().getApplicationContext());
setListAdapter(adapter);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
return inflater.inflate(R.layout.fragment_committee, container, false);
}
public void
refreshList() {
adapter.updateDataSet();
adapter.notifyDataSetChanged();
}
}
Đó là sử dụng bộ chuyển đổi sau:
public class CommitteeAdapter extends BaseAdapter {
private
ArrayList<StudentCommittee> committeeList;
private Context context;
public CommitteeAdapter(Context context) {
this.context = context;
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
public void updateDataSet() {
CommitteeDatabaseAdapter dbAdapter = new CommitteeDatabaseAdapter(context);
committeeList = dbAdapter.readAllCommittees();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
StudentCommittee committee = committeeList.get(position);
View v = vi.inflate(R.layout.list_item_committee, null);
TextView sectionName = (TextView) v.findViewById(R.id.committee_namn);
sectionName.setText(committee.getName());
return v;
}
@Override
public int getCount() {
return committeeList.size();
}
@Override
public StudentCommittee getItem(int position) {
return committeeList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
Dưới đây là xml-file đó quy định cụ thể danh sách (fragment_committee):
<?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="vertical"
android:tag="@string/tag_fragment_committee"
android:background="@color/white" >
<TextView
style="@style/AppsolutText.Headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Festerier" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="@drawable/divider_sliding_menu_item"/>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
style="@style/AppsolutText.Normal"
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Uppdatera för att se en lista över festerier och fadderier. Kräver internetanslutning."/>
</LinearLayout>
Đây là xml cho mục danh sách:
<?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" >
<ImageView
android:id="@+id/committee_symbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" />
<TextView
android:id="@+id/committee_namn"
style="@style/AppsolutText.ListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
Tôi hy vọng rằng bạn có thể tìm ra điều gì sai. Tôi có một listview khác có cùng một id (danh sách) trong một xml-file khác trong dự án. Tôi không biết đó có phải là vấn đề không. Xin hãy giúp tôi giải quyết vấn đề.
bản sao có thể có của [ListView bên trong phân đoạn cung cấp lỗi] (http://stackoverflow.com/questions/12294819/listview-inside-a-fragment-gives-error) – Raghunandan
đăng lớp R.java –