I’m making this activity that accepts data for a form from an xml and renders the form on the screen. Now the code to do the actual rendering is in a separate java file (there are basically 3 types of questions, each with their own method to render the data extracted from xml)Its basically like this.
public void newQuestion(String question, LinearLayout l, Context c){
TextView tv = new TextView(c);
tv.setText(question);
EditText et = new EditText(c);
l.addView(tv);
l.addView(et);
}
So this is my problem – To have this Java file add widgets to the form I need to pass the Context of the activity. Also, I’ll need to be able to access the layout ( simple linear layout) to add to. Can you just pass the R or import it (android.R) in the other java file ? Coz then I can get the context and layout and all requisite ids from R.
I did try importing it. My java classes are in project A and my android activity is a separate project B. So I wrote
import B.src.com.android.*;
and it says ” the import B couldnt be resolved” [I tried B.com.android too . Same error]
You can access R file from any class of project.and you have to import it.