我在programmaticaly中创建了按钮,而不是在xml文件中.然后我想在这个链接中设置LayoutParams:如何以编程方式设置相对布局中按钮的layout_align_parent_right属性?
但是当我试图发射时,我有一个例外.
这是我的代码:
RelativeLayout ll2 = new RelativeLayout(this);
//ll2.setOrientation(LinearLayout.HORIZONTAL);
ImageButton go = new ImageButton(this);
go.setId(cursor.getInt(cursor.getColumnIndex("_id")));
go.setClickable(true);
go.setBackgroundResource(R.drawable.go);
RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams)go.getLayoutParams();
params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); // LogCat said I have Null Pointer Exception in this line
go.setLayoutParams(params1);
go.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i3 = new Intent(RecipesActivity.this, MedicineActivity.class);
i3.putExtra(ShowRecipe, v.getId());
i3.putExtra("Activity", "RecipesActivity");
RecipesActivity.this.startActivity(i3);
}
});
ll2.addView(go);
Run Code Online (Sandbox Code Playgroud)
为什么我的应用会抛出异常?谢谢.
我有一个调用Medicine的数据库,其中有四列:id(主键自动增量),dId(外键),名称和时间.我尝试使用插入函数添加新行.此函数必须返回此添加的id.但是当我从调试器检查这个时,我看到它返回-1.
码:
ContentValues values = new ContentValues();
values.put("RECIPE_ID", recipeId);
values.put("MED_NAME", etMedName.getText().toString());
values.put("MED_TIME", etMedTime.getText().toString());
long mid = sqdb.insert("Medicine", null, values);
Run Code Online (Sandbox Code Playgroud) 我有三行文本视图,例如姓名,电话和地址.我想区分第三行,我想在那里添加图像,为它获得一个圆形边框并更改背景颜色.我有办法吗?
我使用Font Awesome按钮.当我尝试仅在按钮的三个边上设置边框时,我看到边框位于我的按钮周围.这是我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="1dip" android:bottom="1dip" android:left="1dip"><shape>
<solid android:color="#efeae0" />
<stroke android:width="1dp" android:color="#d5cfc3" />
<corners android:topLeftRadius="15dp" />
</shape></item>
</selector>
Run Code Online (Sandbox Code Playgroud)
如何从按钮右侧删除边框?
android ×4
border ×1
font-awesome ×1
imagebutton ×1
insert ×1
layoutparams ×1
sqlite ×1
textview ×1