Ich weiß, dass es ähnliche Fragen gegeben hat, aber ich kann es nicht funktionieren, obwohl ich mir diese anschaue . Die Fehlermeldung lautet:java.lang.RuntimeException: Ihr Inhalt muss eine ListView haben, deren ID-Attribut ist "android.R.id.list"
java.lang.RuntimeException: Ihr Inhalt ein Listview, deren id Attribut haben muss, ist 'android.R.id.list'
. Ich habe versucht, die ID zur Liste zu ändern. In einem anderen. Das, was der Code wie folgt aussieht:
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();
}
}
Es ist die folgende Adapter:
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;
}
}
Hier wird die XML-Datei, die die Liste (fragment_committee) angibt:
<?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>
Hier das xml für den Listeneintrag:
<?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>
Ich hoffe, dass Sie herausfinden können, was los ist. Ich habe eine andere Listenansicht, die dieselbe ID (Liste) in einer anderen XML-Datei innerhalb des Projekts hat. Ich weiß nicht, ob das ein Problem ist. Bitte helfen Sie mir, das Problem zu lösen.
möglich Duplikat von [ListView innerhalb eines Fragments gibt Fehler] (http://stackoverflow.com/questions/12294819/listview-inside-a-fragment-gives-error) – Raghunandan
poste deine R.java-Klasse –