I am currently attempting to fix the error "Your content must have a ListView whose id attribute is 'android.R.list'.
I have found the answer from the following question on Stack Exchange:
Your content must have a ListView whose id attribute is 'android.R.id.list'
I had applied the solution, but then I wished to ask the question:
"Then how do I reference the android-defined XML tag?
However due to the reputation system, I was unable to comment this small question. I apologise for this, but can someone please answer this question?
Thank you in advance.
For your information, this is my listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
And this is what I am trying to pass:
lv = (ListView) convertView.findViewById(R.id.ExceedingList);
And this is the error I'm getting:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.denny.phonebelt/com.example.denny.phonebelt.SettingsMenu}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
Just in case the problem is caused by another bug for some reason, I'll CP the actual code here:
final Button ExceedingLimitButton = (Button)findViewById(R.id.ExceedingLimitButton);
ExceedingLimitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder ExceedingLimitDialog = new AlertDialog.Builder(SettingsMenu.this);
//Setting ListView
LayoutInflater inflater = getLayoutInflater();
View convertView = inflater.inflate(R.layout.exceeding_dialog, null);
lv = (ListView) convertView.findViewById(android.R.id.list);
ArrayAdapter<String> adapter = new ArrayAdapter<>(SettingsMenu.this, android.R.layout.simple_list_item_single_choice, ExceedingSelection);
lv.setAdapter(adapter);
lv.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int SelectedItem = Integer.parseInt(ExceedingSelection[position]);
PhoneBelt.setExceedInt(SelectedItem);
String Selection = getString(R.string.Selection);
String message = (Selection + SelectedItem);
Toast toast = Toast.makeText(SettingsMenu.this, message, Toast.LENGTH_LONG);
toast.show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Toast toast = Toast.makeText(SettingsMenu.this, "You have not selected anything", Toast.LENGTH_SHORT);
toast.show();
}
});
ExceedingLimitDialog.setView(convertView);
ExceedingLimitDialog.setTitle(R.string.Exceeding_Limit_Title);
ExceedingLimitDialog.setMessage(R.string.Exceeding_Limit_Message);
ExceedingLimitDialog.setCancelable(true);
AlertDialog alert = ExceedingLimitDialog.create();
alert.show();
}
});