我相信这可能是一个简单的问题,但是我已经抓耳挠脑了一段时间了,似乎没有任何进展。
基本上我下面的一些例子来建立一个表在android,当我来到setBackgroundResource(R.drawable.cell_shape)
它显示了一个错误,我不确定在哪里添加这个在我的xml表。谁能让我从痛苦中解脱出来?: -/
for (int j = 1; j <= cols; j++) {
TextView tv = new TextView(this);
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tv.setBackgroundResource(R.drawable.cell_shape); // This is my problem here
tv.setPadding(5, 5, 5, 5);
tv.setText("R " + i + ", C" + j);
row.addView(tv);
- 确保cell_shape存在于/res/drawable文件夹
- 确保导入正确的
R.java
yourpkgname.R
而不是android.R
- 如果仍然不能工作,那么清理你的项目。
让我知道它是否适合你