我正在创建一个计算器。进行计算时,我需要将它们显示出来,然后可以点击,这样我就可以删除单个数字。我按照本教程进行了操作,并做到了这一点。唯一的问题是当我运行它时,我得到一个 FC,而我的 logcat 说:
Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
我所有的研究都说将我的 id 更改为android.R.id.list
. 我试过这个,但仍然得到同样的错误。
这是我的代码:
CustomAdapter.java (扩展 ArrayAdapter)
private final Context context;
private final ArrayList<Calculations> items = null;
private final LayoutInflater inflater;
public CustomListAdapter(Context context, int textViewResourceId, ArrayList<Calculations>items){
super(context, textViewResourceId, items);
this.context = context;
this.items = items;
this.inflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View v = convertView != null
? convertView
: infalter.inflate(R.layout.list_item, parent, false);
final Calculations c = items.get(position);
final TextView type = (TextView) v.findViewById(R.id.tvType);
final TextView figure = (TextView) v.findViewById(R.id.tvFullFigure);
final TextView amount = (TextView) v.findViewById(R.id.tvAmount);
type.setText(c.getType());
figure.setText(c.getFigure());
amount.setText(c.getFigureAmount());
return v;
}
aactivity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="15dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:background="@drawable/concret_back"
>
<!--Code remove for brevity-->
<ListView
android:id="@+id/android.R.id.list"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</RelativeLayout>
我已经完成的另一个应用程序遇到了这个问题,但从未找到解决方案。所以我虽然会问为什么我不断收到Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
错误?
感谢您的任何意见。