Inflating a view to a constraint layout from out side the constraint layouts class
up vote
1
down vote
favorite
I'm trying to inflate a view into a constraint layout. Which isn't a problem from with in the activity. But I also want to be able to call it from another classes method called getViews()
... How can I access the constraint layout to inflate the view?
public class chromecastUI_inflater {
Button btn, btn1, fastforward, rewind, play, pause;
TextView title, user, discription, date, streamviews, chromeconnection;
ConstraintLayout constraintLayout1;
Selector selector = new Selector();
Context c;
public chromecastUI_inflater() {
****Edit****
also tried adding the layout via public constructor.
}
public void getViews(View view) {
play = view.findViewById(R.id.play);
pause = view.findViewById(R.id.pause_button);
fastforward = view.findViewById(R.id.fastforward_button);
rewind = view.findViewById(R.id.rewind_button);
btn1 = view.findViewById(R.id.cast_connection_button);
btn = view.findViewById(R.id.cast_connection_button3);
chromeconnection = view.findViewById(R.id.tvcast);
//here is my problem layout
****Edit****
here i've tried adding
view.findViewById
constraintLayout1 = findViewById(R.id.localplayerview);
title = view.findViewById(R.id.title_text_view);
discription = view.findViewById(R.id.discription_text_view);
date = view.findViewById(R.id.date_text_view);
streamviews = view.findViewById(R.id.views_text_view);
user = view.findViewById(R.id.uploadedby_text_view);
constraintLayout1.addView(view);
}
public void inflateViews() {
LayoutInflater inflater = (LayoutInflater) c.getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.layout, null);
getViews(view);
}
public void setUI() {
title.setText(selector.DOCTITLE);
discription.setText(selector.ABOUT);
date.setText(selector.DATE);
streamviews.setText(selector.VIEWS);
user.setText(selector.USER);
}
public void resetUI() {
title.setText("");
discription.setText("");
date.setText("");
streamviews.setText("");
user.setText("");
}
public void Chromecast_Connected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.VISIBLE);
btn1.setVisibility(View.GONE);
}
public void Chromecast_Disconnected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.GONE);
btn1.setVisibility(View.VISIBLE);
}
}
This is where I want to call the method from my local_player
activity
chromecastUI_inflater chromecastUiInflater = new chromecastUI_inflater();
@Override
public void onChromecastConnecting() {
Log.d(getClass().getSimpleName(), "onChromecastConnecting");
chromecastUiInflater.inflateViews();
}
@Override
public void onChromecastConnected(ChromecastYouTubePlayerContext chromecastYouTubePlayerContext) {
Log.d(getClass().getSimpleName(), "onChromecastConnected");
chromecastUiInflater.setUI();
chromecastUiInflater.Chromecast_Connected();
initializeCastPlayer(chromecastYouTubePlayerContext);
}
Sorry guys, I'm used to inflating the views from inside an activity. Any help please.
java android view layout-inflater
add a comment |
up vote
1
down vote
favorite
I'm trying to inflate a view into a constraint layout. Which isn't a problem from with in the activity. But I also want to be able to call it from another classes method called getViews()
... How can I access the constraint layout to inflate the view?
public class chromecastUI_inflater {
Button btn, btn1, fastforward, rewind, play, pause;
TextView title, user, discription, date, streamviews, chromeconnection;
ConstraintLayout constraintLayout1;
Selector selector = new Selector();
Context c;
public chromecastUI_inflater() {
****Edit****
also tried adding the layout via public constructor.
}
public void getViews(View view) {
play = view.findViewById(R.id.play);
pause = view.findViewById(R.id.pause_button);
fastforward = view.findViewById(R.id.fastforward_button);
rewind = view.findViewById(R.id.rewind_button);
btn1 = view.findViewById(R.id.cast_connection_button);
btn = view.findViewById(R.id.cast_connection_button3);
chromeconnection = view.findViewById(R.id.tvcast);
//here is my problem layout
****Edit****
here i've tried adding
view.findViewById
constraintLayout1 = findViewById(R.id.localplayerview);
title = view.findViewById(R.id.title_text_view);
discription = view.findViewById(R.id.discription_text_view);
date = view.findViewById(R.id.date_text_view);
streamviews = view.findViewById(R.id.views_text_view);
user = view.findViewById(R.id.uploadedby_text_view);
constraintLayout1.addView(view);
}
public void inflateViews() {
LayoutInflater inflater = (LayoutInflater) c.getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.layout, null);
getViews(view);
}
public void setUI() {
title.setText(selector.DOCTITLE);
discription.setText(selector.ABOUT);
date.setText(selector.DATE);
streamviews.setText(selector.VIEWS);
user.setText(selector.USER);
}
public void resetUI() {
title.setText("");
discription.setText("");
date.setText("");
streamviews.setText("");
user.setText("");
}
public void Chromecast_Connected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.VISIBLE);
btn1.setVisibility(View.GONE);
}
public void Chromecast_Disconnected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.GONE);
btn1.setVisibility(View.VISIBLE);
}
}
This is where I want to call the method from my local_player
activity
chromecastUI_inflater chromecastUiInflater = new chromecastUI_inflater();
@Override
public void onChromecastConnecting() {
Log.d(getClass().getSimpleName(), "onChromecastConnecting");
chromecastUiInflater.inflateViews();
}
@Override
public void onChromecastConnected(ChromecastYouTubePlayerContext chromecastYouTubePlayerContext) {
Log.d(getClass().getSimpleName(), "onChromecastConnected");
chromecastUiInflater.setUI();
chromecastUiInflater.Chromecast_Connected();
initializeCastPlayer(chromecastYouTubePlayerContext);
}
Sorry guys, I'm used to inflating the views from inside an activity. Any help please.
java android view layout-inflater
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to inflate a view into a constraint layout. Which isn't a problem from with in the activity. But I also want to be able to call it from another classes method called getViews()
... How can I access the constraint layout to inflate the view?
public class chromecastUI_inflater {
Button btn, btn1, fastforward, rewind, play, pause;
TextView title, user, discription, date, streamviews, chromeconnection;
ConstraintLayout constraintLayout1;
Selector selector = new Selector();
Context c;
public chromecastUI_inflater() {
****Edit****
also tried adding the layout via public constructor.
}
public void getViews(View view) {
play = view.findViewById(R.id.play);
pause = view.findViewById(R.id.pause_button);
fastforward = view.findViewById(R.id.fastforward_button);
rewind = view.findViewById(R.id.rewind_button);
btn1 = view.findViewById(R.id.cast_connection_button);
btn = view.findViewById(R.id.cast_connection_button3);
chromeconnection = view.findViewById(R.id.tvcast);
//here is my problem layout
****Edit****
here i've tried adding
view.findViewById
constraintLayout1 = findViewById(R.id.localplayerview);
title = view.findViewById(R.id.title_text_view);
discription = view.findViewById(R.id.discription_text_view);
date = view.findViewById(R.id.date_text_view);
streamviews = view.findViewById(R.id.views_text_view);
user = view.findViewById(R.id.uploadedby_text_view);
constraintLayout1.addView(view);
}
public void inflateViews() {
LayoutInflater inflater = (LayoutInflater) c.getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.layout, null);
getViews(view);
}
public void setUI() {
title.setText(selector.DOCTITLE);
discription.setText(selector.ABOUT);
date.setText(selector.DATE);
streamviews.setText(selector.VIEWS);
user.setText(selector.USER);
}
public void resetUI() {
title.setText("");
discription.setText("");
date.setText("");
streamviews.setText("");
user.setText("");
}
public void Chromecast_Connected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.VISIBLE);
btn1.setVisibility(View.GONE);
}
public void Chromecast_Disconnected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.GONE);
btn1.setVisibility(View.VISIBLE);
}
}
This is where I want to call the method from my local_player
activity
chromecastUI_inflater chromecastUiInflater = new chromecastUI_inflater();
@Override
public void onChromecastConnecting() {
Log.d(getClass().getSimpleName(), "onChromecastConnecting");
chromecastUiInflater.inflateViews();
}
@Override
public void onChromecastConnected(ChromecastYouTubePlayerContext chromecastYouTubePlayerContext) {
Log.d(getClass().getSimpleName(), "onChromecastConnected");
chromecastUiInflater.setUI();
chromecastUiInflater.Chromecast_Connected();
initializeCastPlayer(chromecastYouTubePlayerContext);
}
Sorry guys, I'm used to inflating the views from inside an activity. Any help please.
java android view layout-inflater
I'm trying to inflate a view into a constraint layout. Which isn't a problem from with in the activity. But I also want to be able to call it from another classes method called getViews()
... How can I access the constraint layout to inflate the view?
public class chromecastUI_inflater {
Button btn, btn1, fastforward, rewind, play, pause;
TextView title, user, discription, date, streamviews, chromeconnection;
ConstraintLayout constraintLayout1;
Selector selector = new Selector();
Context c;
public chromecastUI_inflater() {
****Edit****
also tried adding the layout via public constructor.
}
public void getViews(View view) {
play = view.findViewById(R.id.play);
pause = view.findViewById(R.id.pause_button);
fastforward = view.findViewById(R.id.fastforward_button);
rewind = view.findViewById(R.id.rewind_button);
btn1 = view.findViewById(R.id.cast_connection_button);
btn = view.findViewById(R.id.cast_connection_button3);
chromeconnection = view.findViewById(R.id.tvcast);
//here is my problem layout
****Edit****
here i've tried adding
view.findViewById
constraintLayout1 = findViewById(R.id.localplayerview);
title = view.findViewById(R.id.title_text_view);
discription = view.findViewById(R.id.discription_text_view);
date = view.findViewById(R.id.date_text_view);
streamviews = view.findViewById(R.id.views_text_view);
user = view.findViewById(R.id.uploadedby_text_view);
constraintLayout1.addView(view);
}
public void inflateViews() {
LayoutInflater inflater = (LayoutInflater) c.getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.layout, null);
getViews(view);
}
public void setUI() {
title.setText(selector.DOCTITLE);
discription.setText(selector.ABOUT);
date.setText(selector.DATE);
streamviews.setText(selector.VIEWS);
user.setText(selector.USER);
}
public void resetUI() {
title.setText("");
discription.setText("");
date.setText("");
streamviews.setText("");
user.setText("");
}
public void Chromecast_Connected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.VISIBLE);
btn1.setVisibility(View.GONE);
}
public void Chromecast_Disconnected() {
chromeconnection.setText("Chromecast is connected");
btn.setVisibility(View.GONE);
btn1.setVisibility(View.VISIBLE);
}
}
This is where I want to call the method from my local_player
activity
chromecastUI_inflater chromecastUiInflater = new chromecastUI_inflater();
@Override
public void onChromecastConnecting() {
Log.d(getClass().getSimpleName(), "onChromecastConnecting");
chromecastUiInflater.inflateViews();
}
@Override
public void onChromecastConnected(ChromecastYouTubePlayerContext chromecastYouTubePlayerContext) {
Log.d(getClass().getSimpleName(), "onChromecastConnected");
chromecastUiInflater.setUI();
chromecastUiInflater.Chromecast_Connected();
initializeCastPlayer(chromecastYouTubePlayerContext);
}
Sorry guys, I'm used to inflating the views from inside an activity. Any help please.
java android view layout-inflater
java android view layout-inflater
edited Nov 8 at 12:26
asked Nov 8 at 11:36
markharrop
297113
297113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
so here is how i fixed it. i had to make a view called root view in my inflate view method. then from my activity call the rootview as constraint layout.
public void inflateViews(View rootview,Context c){
constraintLayout1 = rootview.findViewById(R.id.localplayerview);
LayoutInflater inflater = (LayoutInflater)c.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout,null);
getViews(view);
}
then i had to make a getStrings method to fill my textviews from the inflated view
public void getStrings_fromLocalPlayer(String title,String synopsis, String user, String views, String date){
doctitle = title;
docsynopsis = synopsis;
docuser = user;
docviews = views;
docdate = date;
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
so here is how i fixed it. i had to make a view called root view in my inflate view method. then from my activity call the rootview as constraint layout.
public void inflateViews(View rootview,Context c){
constraintLayout1 = rootview.findViewById(R.id.localplayerview);
LayoutInflater inflater = (LayoutInflater)c.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout,null);
getViews(view);
}
then i had to make a getStrings method to fill my textviews from the inflated view
public void getStrings_fromLocalPlayer(String title,String synopsis, String user, String views, String date){
doctitle = title;
docsynopsis = synopsis;
docuser = user;
docviews = views;
docdate = date;
}
add a comment |
up vote
1
down vote
so here is how i fixed it. i had to make a view called root view in my inflate view method. then from my activity call the rootview as constraint layout.
public void inflateViews(View rootview,Context c){
constraintLayout1 = rootview.findViewById(R.id.localplayerview);
LayoutInflater inflater = (LayoutInflater)c.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout,null);
getViews(view);
}
then i had to make a getStrings method to fill my textviews from the inflated view
public void getStrings_fromLocalPlayer(String title,String synopsis, String user, String views, String date){
doctitle = title;
docsynopsis = synopsis;
docuser = user;
docviews = views;
docdate = date;
}
add a comment |
up vote
1
down vote
up vote
1
down vote
so here is how i fixed it. i had to make a view called root view in my inflate view method. then from my activity call the rootview as constraint layout.
public void inflateViews(View rootview,Context c){
constraintLayout1 = rootview.findViewById(R.id.localplayerview);
LayoutInflater inflater = (LayoutInflater)c.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout,null);
getViews(view);
}
then i had to make a getStrings method to fill my textviews from the inflated view
public void getStrings_fromLocalPlayer(String title,String synopsis, String user, String views, String date){
doctitle = title;
docsynopsis = synopsis;
docuser = user;
docviews = views;
docdate = date;
}
so here is how i fixed it. i had to make a view called root view in my inflate view method. then from my activity call the rootview as constraint layout.
public void inflateViews(View rootview,Context c){
constraintLayout1 = rootview.findViewById(R.id.localplayerview);
LayoutInflater inflater = (LayoutInflater)c.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout,null);
getViews(view);
}
then i had to make a getStrings method to fill my textviews from the inflated view
public void getStrings_fromLocalPlayer(String title,String synopsis, String user, String views, String date){
doctitle = title;
docsynopsis = synopsis;
docuser = user;
docviews = views;
docdate = date;
}
answered Nov 8 at 16:58
markharrop
297113
297113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206961%2finflating-a-view-to-a-constraint-layout-from-out-side-the-constraint-layouts-cla%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown