OnClickListener not firing in fragment
I've already searched through the forum for answers, but I couldn't find any question that completely matches my situation.
I'm having a problem firing an onclicklistener. The same piece of code works in other parts of application, which confuses me.
This is my code:
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
And the XML
<Button
android:id="@+id/billede_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Tilføj billede"
/>
<TextView android:id="@+id/billede_path"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center" />
<Button android:id="@+id/addOpskrift"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
java
add a comment |
I've already searched through the forum for answers, but I couldn't find any question that completely matches my situation.
I'm having a problem firing an onclicklistener. The same piece of code works in other parts of application, which confuses me.
This is my code:
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
And the XML
<Button
android:id="@+id/billede_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Tilføj billede"
/>
<TextView android:id="@+id/billede_path"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center" />
<Button android:id="@+id/addOpskrift"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
java
What is this method? "Tilføjopskrift();"? I wouldnt recommend you to use special characters just like "ø"
– Brank Victoria
Nov 21 '18 at 12:37
It is a method that adds something into a arraylist, I've changed the name but no changes
– Mohammad Saad
Nov 21 '18 at 12:39
I think you didn't post your whole XML, cause I don't see the definition ofbillede_button
– Brank Victoria
Nov 21 '18 at 12:42
Changing the name of the method will not debug any logic, I think... That recommendation targets something different: international readability
– deHaar
Nov 21 '18 at 12:43
I think you must change your method name.
– Cagri Yalcin
Nov 21 '18 at 13:16
add a comment |
I've already searched through the forum for answers, but I couldn't find any question that completely matches my situation.
I'm having a problem firing an onclicklistener. The same piece of code works in other parts of application, which confuses me.
This is my code:
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
And the XML
<Button
android:id="@+id/billede_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Tilføj billede"
/>
<TextView android:id="@+id/billede_path"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center" />
<Button android:id="@+id/addOpskrift"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
java
I've already searched through the forum for answers, but I couldn't find any question that completely matches my situation.
I'm having a problem firing an onclicklistener. The same piece of code works in other parts of application, which confuses me.
This is my code:
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
And the XML
<Button
android:id="@+id/billede_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Tilføj billede"
/>
<TextView android:id="@+id/billede_path"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center" />
<Button android:id="@+id/addOpskrift"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
java
java
edited Nov 21 '18 at 12:50
Mohammad Saad
asked Nov 21 '18 at 12:33
Mohammad SaadMohammad Saad
326
326
What is this method? "Tilføjopskrift();"? I wouldnt recommend you to use special characters just like "ø"
– Brank Victoria
Nov 21 '18 at 12:37
It is a method that adds something into a arraylist, I've changed the name but no changes
– Mohammad Saad
Nov 21 '18 at 12:39
I think you didn't post your whole XML, cause I don't see the definition ofbillede_button
– Brank Victoria
Nov 21 '18 at 12:42
Changing the name of the method will not debug any logic, I think... That recommendation targets something different: international readability
– deHaar
Nov 21 '18 at 12:43
I think you must change your method name.
– Cagri Yalcin
Nov 21 '18 at 13:16
add a comment |
What is this method? "Tilføjopskrift();"? I wouldnt recommend you to use special characters just like "ø"
– Brank Victoria
Nov 21 '18 at 12:37
It is a method that adds something into a arraylist, I've changed the name but no changes
– Mohammad Saad
Nov 21 '18 at 12:39
I think you didn't post your whole XML, cause I don't see the definition ofbillede_button
– Brank Victoria
Nov 21 '18 at 12:42
Changing the name of the method will not debug any logic, I think... That recommendation targets something different: international readability
– deHaar
Nov 21 '18 at 12:43
I think you must change your method name.
– Cagri Yalcin
Nov 21 '18 at 13:16
What is this method? "Tilføjopskrift();"? I wouldnt recommend you to use special characters just like "ø"
– Brank Victoria
Nov 21 '18 at 12:37
What is this method? "Tilføjopskrift();"? I wouldnt recommend you to use special characters just like "ø"
– Brank Victoria
Nov 21 '18 at 12:37
It is a method that adds something into a arraylist, I've changed the name but no changes
– Mohammad Saad
Nov 21 '18 at 12:39
It is a method that adds something into a arraylist, I've changed the name but no changes
– Mohammad Saad
Nov 21 '18 at 12:39
I think you didn't post your whole XML, cause I don't see the definition of
billede_button– Brank Victoria
Nov 21 '18 at 12:42
I think you didn't post your whole XML, cause I don't see the definition of
billede_button– Brank Victoria
Nov 21 '18 at 12:42
Changing the name of the method will not debug any logic, I think... That recommendation targets something different: international readability
– deHaar
Nov 21 '18 at 12:43
Changing the name of the method will not debug any logic, I think... That recommendation targets something different: international readability
– deHaar
Nov 21 '18 at 12:43
I think you must change your method name.
– Cagri Yalcin
Nov 21 '18 at 13:16
I think you must change your method name.
– Cagri Yalcin
Nov 21 '18 at 13:16
add a comment |
3 Answers
3
active
oldest
votes
In your XML you have given id opret_knap to you Button
<Button
android:id="@+id/opret_knap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
But you are accessing it with addOpskrift
Change
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
to
opret_knap = (Button) view.findViewById(R.id.opret_knap);
Thanks. I've changed it couple of times while trying to fix the issue. They match now, but yet it doesn't work.
– Mohammad Saad
Nov 21 '18 at 12:49
add a comment |
The problem seems to be that you are not specifying the layout your fragment should access.
Instead of:
super.onCreateView()
Use
View view = inflater.inflate(R.layout.xyz, container, false);
Hope it helps.
Thanks for the suggestion. It didn't work.
– Mohammad Saad
Nov 21 '18 at 13:03
add a comment |
Your problem is that your not instanciate correctely the new view.
You need use:
View view = inflater.inflate(R.layout.your_file_name, container, false);
instead of:
View view = super.onCreateView(inflater, container, savedInstanceState);.
Just copy and paste.
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.your_file_name, container, false);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
Thanks. I've already tried to change it. Still no changes.
– Mohammad Saad
Nov 21 '18 at 13:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53412138%2fonclicklistener-not-firing-in-fragment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your XML you have given id opret_knap to you Button
<Button
android:id="@+id/opret_knap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
But you are accessing it with addOpskrift
Change
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
to
opret_knap = (Button) view.findViewById(R.id.opret_knap);
Thanks. I've changed it couple of times while trying to fix the issue. They match now, but yet it doesn't work.
– Mohammad Saad
Nov 21 '18 at 12:49
add a comment |
In your XML you have given id opret_knap to you Button
<Button
android:id="@+id/opret_knap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
But you are accessing it with addOpskrift
Change
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
to
opret_knap = (Button) view.findViewById(R.id.opret_knap);
Thanks. I've changed it couple of times while trying to fix the issue. They match now, but yet it doesn't work.
– Mohammad Saad
Nov 21 '18 at 12:49
add a comment |
In your XML you have given id opret_knap to you Button
<Button
android:id="@+id/opret_knap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
But you are accessing it with addOpskrift
Change
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
to
opret_knap = (Button) view.findViewById(R.id.opret_knap);
In your XML you have given id opret_knap to you Button
<Button
android:id="@+id/opret_knap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="Opret"/>
But you are accessing it with addOpskrift
Change
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
to
opret_knap = (Button) view.findViewById(R.id.opret_knap);
answered Nov 21 '18 at 12:43
Prithvi BholaPrithvi Bhola
1,120320
1,120320
Thanks. I've changed it couple of times while trying to fix the issue. They match now, but yet it doesn't work.
– Mohammad Saad
Nov 21 '18 at 12:49
add a comment |
Thanks. I've changed it couple of times while trying to fix the issue. They match now, but yet it doesn't work.
– Mohammad Saad
Nov 21 '18 at 12:49
Thanks. I've changed it couple of times while trying to fix the issue. They match now, but yet it doesn't work.
– Mohammad Saad
Nov 21 '18 at 12:49
Thanks. I've changed it couple of times while trying to fix the issue. They match now, but yet it doesn't work.
– Mohammad Saad
Nov 21 '18 at 12:49
add a comment |
The problem seems to be that you are not specifying the layout your fragment should access.
Instead of:
super.onCreateView()
Use
View view = inflater.inflate(R.layout.xyz, container, false);
Hope it helps.
Thanks for the suggestion. It didn't work.
– Mohammad Saad
Nov 21 '18 at 13:03
add a comment |
The problem seems to be that you are not specifying the layout your fragment should access.
Instead of:
super.onCreateView()
Use
View view = inflater.inflate(R.layout.xyz, container, false);
Hope it helps.
Thanks for the suggestion. It didn't work.
– Mohammad Saad
Nov 21 '18 at 13:03
add a comment |
The problem seems to be that you are not specifying the layout your fragment should access.
Instead of:
super.onCreateView()
Use
View view = inflater.inflate(R.layout.xyz, container, false);
Hope it helps.
The problem seems to be that you are not specifying the layout your fragment should access.
Instead of:
super.onCreateView()
Use
View view = inflater.inflate(R.layout.xyz, container, false);
Hope it helps.
answered Nov 21 '18 at 12:58
Sarthak GroverSarthak Grover
7810
7810
Thanks for the suggestion. It didn't work.
– Mohammad Saad
Nov 21 '18 at 13:03
add a comment |
Thanks for the suggestion. It didn't work.
– Mohammad Saad
Nov 21 '18 at 13:03
Thanks for the suggestion. It didn't work.
– Mohammad Saad
Nov 21 '18 at 13:03
Thanks for the suggestion. It didn't work.
– Mohammad Saad
Nov 21 '18 at 13:03
add a comment |
Your problem is that your not instanciate correctely the new view.
You need use:
View view = inflater.inflate(R.layout.your_file_name, container, false);
instead of:
View view = super.onCreateView(inflater, container, savedInstanceState);.
Just copy and paste.
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.your_file_name, container, false);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
Thanks. I've already tried to change it. Still no changes.
– Mohammad Saad
Nov 21 '18 at 13:15
add a comment |
Your problem is that your not instanciate correctely the new view.
You need use:
View view = inflater.inflate(R.layout.your_file_name, container, false);
instead of:
View view = super.onCreateView(inflater, container, savedInstanceState);.
Just copy and paste.
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.your_file_name, container, false);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
Thanks. I've already tried to change it. Still no changes.
– Mohammad Saad
Nov 21 '18 at 13:15
add a comment |
Your problem is that your not instanciate correctely the new view.
You need use:
View view = inflater.inflate(R.layout.your_file_name, container, false);
instead of:
View view = super.onCreateView(inflater, container, savedInstanceState);.
Just copy and paste.
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.your_file_name, container, false);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
Your problem is that your not instanciate correctely the new view.
You need use:
View view = inflater.inflate(R.layout.your_file_name, container, false);
instead of:
View view = super.onCreateView(inflater, container, savedInstanceState);.
Just copy and paste.
private static final int RESULT_LOAD_IMAGES = 1;
TextView filepath_name;
EditText varighed, navn;
Spinner genre, kategori;
Button uploadImg, opret_knap;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.your_file_name, container, false);
uploadImg = (Button) view.findViewById(R.id.billede_button);
opret_knap = (Button) view.findViewById(R.id.addOpskrift);
varighed = (EditText) view.findViewById(R.id.opskrift_varighed);
navn = (EditText) view.findViewById(R.id.opskrift_navn);
genre = (Spinner) view.findViewById(R.id.opskrift_genre);
kategori = (Spinner) view.findViewById(R.id.opskrift_kategori);
filepath_name = (TextView) view.findViewById(R.id.billede_path);
uploadImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGES);
}
});
opret_knap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Tilføjopskrift();
}
});
return view;
}
answered Nov 21 '18 at 13:08
AugustoAugusto
527521
527521
Thanks. I've already tried to change it. Still no changes.
– Mohammad Saad
Nov 21 '18 at 13:15
add a comment |
Thanks. I've already tried to change it. Still no changes.
– Mohammad Saad
Nov 21 '18 at 13:15
Thanks. I've already tried to change it. Still no changes.
– Mohammad Saad
Nov 21 '18 at 13:15
Thanks. I've already tried to change it. Still no changes.
– Mohammad Saad
Nov 21 '18 at 13:15
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.
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%2f53412138%2fonclicklistener-not-firing-in-fragment%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
What is this method? "Tilføjopskrift();"? I wouldnt recommend you to use special characters just like "ø"
– Brank Victoria
Nov 21 '18 at 12:37
It is a method that adds something into a arraylist, I've changed the name but no changes
– Mohammad Saad
Nov 21 '18 at 12:39
I think you didn't post your whole XML, cause I don't see the definition of
billede_button– Brank Victoria
Nov 21 '18 at 12:42
Changing the name of the method will not debug any logic, I think... That recommendation targets something different: international readability
– deHaar
Nov 21 '18 at 12:43
I think you must change your method name.
– Cagri Yalcin
Nov 21 '18 at 13:16