This question has been asked a lot in different situations, but for over a day I can't find an answer that fixes my error.
I have an xml file called activity_single_touch.xml
inside res/layout
folder.
This file is used to add views like buttons, but I also want to be able to edit it "live" (the user can draw on screen).
Following android guide, I tried using XmlPullParser
in my main java code like so:
public class SingleTouchActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_single_touch);
XmlPullParser parser = getResources().getXml(R.xml.activity_single_touch);
AttributeSet attributes = Xml.asAttributeSet(parser);
setContentView(new SingleTouchEventView(this, attributes));
}
public class SingleTouchEventView extends View {
...
}
}
The rest of the code uses OnDraw
and OnTouchEvent
to draw a path according to user movement, and then invalidate.
The error I am getting at the moment is "cannot resolve symbol 'xml'". How can I fix this?
p.s: Things I have tried (and have failed): Using
XmlPullParser parser =getResources().getXml(R.layout.activity_single_touch);
and getting "expected xml element" error,
I've read over
this guide
these answeres
these as well
use of streams
use of context
moving the xml file to a different folder(could not move it)
this guide
and of course searching google and some more stackOverflow questions and answers.