im new to android programming.
im wondering if it is possible to generate ID i created in java class to r.java
The ID i want to generate is nBtnLayoutlist.
public class classABC extends Activity {
private int nBtnLayoutlist = 20;
private OnClickListener onClick() {
return new OnClickListener() {
public void onClick(View v) {
nBtnLayout = (LinearLayout)findViewById(R.id.nBtnLayoutList);
}
};
}
private LinearLayout newBtnLayout(){
LinearLayout nBtnLayout = new LinearLayout(this);
final LayoutParams lparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
nBtnLayout.setOrientation(LinearLayout.VERTICAL);
nBtnLayout.setLayoutParams(lparams);
nBtnLayout.setWeightSum(100);
nBtnLayout.setId(nBtnLayoutList);
return nBtnLayout;
}
The ids in R.java are generated at build time from the contents of your .xml files. R.java cannot be modified by hand and it cannot be modified at run time.
If you want, you can define an id resource by declaring it in some file in
res/values(the file can have any name):You can always set the id of a view in your layout by calling
setId(int)(as you are already doing).EDIT: If you want to use a constant in the call such as
then you need to use the same constant in calls such as