我正在创建一个计算器。在进行计算时,我需要显示它们,然后单击,这样我就可以删除单个数字。我遵循了this教程,并且做到了这一点。唯一的问题是当我运行它时,我得到一个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;
}
acitivty_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'
错误?
感谢您的任何意见。
答案 0 :(得分:3)
从
更改ListView ID <ListView
android:id="@+id/android.R.id.list"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
到
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />