Xamarin Adapter FindViewById returns null
Not sure what I'm doing wrong here but FindViewById always returns null for my custom row view:
public override View GetView(int position, View convertView, ViewGroup parent) {
var view = convertView;
var item = items[position];
if(view == null)
view = context.LayoutInflater.Inflate(Resource.Layout.listview_row, null);
var nameTextView = view.FindViewById<TextView>(Resource.Id.nameTextView);
var priceTextView = view.FindViewById<TextView>(Resource.Id.priceTextView);
nameTextView.Text = item.Name;
priceTextView.Text = (item.Price ?? 0M).ToString("#.00");
return view;
}
This is the view code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView id="@+id/nameTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_margin="5dp" />
<TextView id="@+id/priceTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_margin="5dp" />
</LinearLayout>
The view inflates correctly but for some reason both TextViews are always null after the call to FindViewById.
I have tried cleaning and rebuilding the project but that did not work. Not sure why this is not working.
Thank you for any pointers.
android-listview xamarin.android
add a comment |
Not sure what I'm doing wrong here but FindViewById always returns null for my custom row view:
public override View GetView(int position, View convertView, ViewGroup parent) {
var view = convertView;
var item = items[position];
if(view == null)
view = context.LayoutInflater.Inflate(Resource.Layout.listview_row, null);
var nameTextView = view.FindViewById<TextView>(Resource.Id.nameTextView);
var priceTextView = view.FindViewById<TextView>(Resource.Id.priceTextView);
nameTextView.Text = item.Name;
priceTextView.Text = (item.Price ?? 0M).ToString("#.00");
return view;
}
This is the view code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView id="@+id/nameTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_margin="5dp" />
<TextView id="@+id/priceTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_margin="5dp" />
</LinearLayout>
The view inflates correctly but for some reason both TextViews are always null after the call to FindViewById.
I have tried cleaning and rebuilding the project but that did not work. Not sure why this is not working.
Thank you for any pointers.
android-listview xamarin.android
add a comment |
Not sure what I'm doing wrong here but FindViewById always returns null for my custom row view:
public override View GetView(int position, View convertView, ViewGroup parent) {
var view = convertView;
var item = items[position];
if(view == null)
view = context.LayoutInflater.Inflate(Resource.Layout.listview_row, null);
var nameTextView = view.FindViewById<TextView>(Resource.Id.nameTextView);
var priceTextView = view.FindViewById<TextView>(Resource.Id.priceTextView);
nameTextView.Text = item.Name;
priceTextView.Text = (item.Price ?? 0M).ToString("#.00");
return view;
}
This is the view code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView id="@+id/nameTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_margin="5dp" />
<TextView id="@+id/priceTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_margin="5dp" />
</LinearLayout>
The view inflates correctly but for some reason both TextViews are always null after the call to FindViewById.
I have tried cleaning and rebuilding the project but that did not work. Not sure why this is not working.
Thank you for any pointers.
android-listview xamarin.android
Not sure what I'm doing wrong here but FindViewById always returns null for my custom row view:
public override View GetView(int position, View convertView, ViewGroup parent) {
var view = convertView;
var item = items[position];
if(view == null)
view = context.LayoutInflater.Inflate(Resource.Layout.listview_row, null);
var nameTextView = view.FindViewById<TextView>(Resource.Id.nameTextView);
var priceTextView = view.FindViewById<TextView>(Resource.Id.priceTextView);
nameTextView.Text = item.Name;
priceTextView.Text = (item.Price ?? 0M).ToString("#.00");
return view;
}
This is the view code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView id="@+id/nameTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_margin="5dp" />
<TextView id="@+id/priceTextView"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_margin="5dp" />
</LinearLayout>
The view inflates correctly but for some reason both TextViews are always null after the call to FindViewById.
I have tried cleaning and rebuilding the project but that did not work. Not sure why this is not working.
Thank you for any pointers.
android-listview xamarin.android
android-listview xamarin.android
asked Dec 27 at 12:56
Fernando
3301412
3301412
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You are providing an id with the wrong way hence it is not getting registered in Resource designer
Try this :
android:id="@+id/nameTextView"
android:id="@+id/priceTextView"
Thanks, that's probably when I re-wrote the code it worked. It drove me crazy and I just couldn't see it.
– Fernando
2 days ago
Its okay no problem at all goodluck.
– G.hakim
2 days ago
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%2f53945485%2fxamarin-adapter-findviewbyid-returns-null%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are providing an id with the wrong way hence it is not getting registered in Resource designer
Try this :
android:id="@+id/nameTextView"
android:id="@+id/priceTextView"
Thanks, that's probably when I re-wrote the code it worked. It drove me crazy and I just couldn't see it.
– Fernando
2 days ago
Its okay no problem at all goodluck.
– G.hakim
2 days ago
add a comment |
You are providing an id with the wrong way hence it is not getting registered in Resource designer
Try this :
android:id="@+id/nameTextView"
android:id="@+id/priceTextView"
Thanks, that's probably when I re-wrote the code it worked. It drove me crazy and I just couldn't see it.
– Fernando
2 days ago
Its okay no problem at all goodluck.
– G.hakim
2 days ago
add a comment |
You are providing an id with the wrong way hence it is not getting registered in Resource designer
Try this :
android:id="@+id/nameTextView"
android:id="@+id/priceTextView"
You are providing an id with the wrong way hence it is not getting registered in Resource designer
Try this :
android:id="@+id/nameTextView"
android:id="@+id/priceTextView"
answered 2 days ago
G.hakim
2,8191627
2,8191627
Thanks, that's probably when I re-wrote the code it worked. It drove me crazy and I just couldn't see it.
– Fernando
2 days ago
Its okay no problem at all goodluck.
– G.hakim
2 days ago
add a comment |
Thanks, that's probably when I re-wrote the code it worked. It drove me crazy and I just couldn't see it.
– Fernando
2 days ago
Its okay no problem at all goodluck.
– G.hakim
2 days ago
Thanks, that's probably when I re-wrote the code it worked. It drove me crazy and I just couldn't see it.
– Fernando
2 days ago
Thanks, that's probably when I re-wrote the code it worked. It drove me crazy and I just couldn't see it.
– Fernando
2 days ago
Its okay no problem at all goodluck.
– G.hakim
2 days ago
Its okay no problem at all goodluck.
– G.hakim
2 days ago
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%2f53945485%2fxamarin-adapter-findviewbyid-returns-null%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