I've got a strange problem with FFImageLoading. Compiler don't show any error, but while application is starting on device, there is thrown an exception:
System.NullReferenceException.
Code:
C#
private void setUserImage()
{
ImageService.Instance.Initialize();
imgThunbailUsername = FindViewById<ImageViewAsync>(Resource.Id.imgDisplay);
string url = #"https://lh4.googleusercontent.com/-Lfgi-xEMwuk/VNWoy8EDWcI/AAAAAAAAACk/rwsluNfhSZY/w1486-h832-no/photo.jpg";
ImageService.Instance.LoadUrl(url)
.Retry(3, 200)
.DownSample(60, 60)
.Into(imgThunbailUsername); // compiler points here with an exception
}
XML
<FFImageLoading.Views.ImageViewAsync
android:id="#+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter" />
I'd be thankful for any tip, idea, or even another good tool for images in Xamarin.
Okay, I found out what's wrong. XML below is not directly under ViewModel.
<FFImageLoading.Views.ImageViewAsync
android:id="#+id/imgDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter" />
XML over there is called inside
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
android:id="#+id/nav_view"
app:headerLayout="#layout/drawer_header" <!-- here -->
app:menu="#menu/navmenu" />
</android.support.v4.widget.DrawerLayout>
So in this case I have to call properly view:
View headerLayout = navigationView.InflateHeaderView(Resource.Layout.drawer_header);
and so on use FindViewByIdlike that:
imgThunbailUsername = headerLayout.FindViewById<ImageViewAsync>(Resource.Id.imgDisplay);
So all I need to do is just get a View headerlayout with InflateHeaderView.
Related
I am newbie in Xamarin Android and MvvmCross and I have been trying to achieve alternate rows background for MvxListView. Below is my code for MvxListView
<Mvx.MvxListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#null"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/llSubtotal"
android:cacheColorHint="#android:color/transparent"
local:MvxBind="ItemsSource Items;ItemClick ItemSelectedCommand"
local:MvxItemTemplate="#layout/listviewitem"
android:id="#+id/mvxLVCustomerItemList" />
Yes, I am binding itemsource of listview from ViewModel.
Template for above Listview is ListViewItem.axml as below -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:id="#+id/lvItemTemplate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/odd">
<Mvx.MvxImageView
android:layout_width="150dp"
android:layout_height="fill_parent"
android:id="#+id/ivItemImage"
android:textSize="40dp"
android:layout_gravity="center_horizontal|center"
local:MvxBind="ImageUrl StripUrl" />
<TextView
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:id="#+id/tvItemName"
android:layout_height="fill_parent"
local:MvxBind="Text Title" />
</LinearLayout>
I tried to achieve alternate rows using custom adapter but in that case listview does not show data. Somehow I failed for it due to my lack of knowledge on Android or MvvmCross.
Any Help will be highly appreciated.
Please note that this project is in Xamarin and has only Android app in it. There is no UWP or other in my project this is completely Xamarin Android with MvvmCross.
Thanks.
My problem is I can't make the button I added in my custom listview to be clickable.
Here is the XML file of my custom listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="335dp"
android:layout_height="100dp"
android:minHeight="80dp"
android:maxHeight="250dp"
android:background="#ffffff"
android:id="#+id/list"
android:baselineAligned="false"
android:longClickable="false"
android:descendantFocusability="blocksDescendants"
android:clickable="false">
<Button
android:background="#drawable/grbgCan"
android:layout_width="15dp"
android:layout_height="20dp"
android:id="#+id/deleteMemo"
android:layout_gravity="start"
android:layout_marginLeft="270dp"
android:layout_marginTop="5dp"
android:duplicateParentState="false"
android:clickable="true" />
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/id"
android:layout_marginLeft="290dp"
android:layout_marginTop="-20dp"
android:layout_marginRight="15dp"
android:clickable="true" />
<TextView
android:id="#+id/top"
android:text="Title"
android:textColor="#ff7e7777"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="255.5dp"
android:layout_height="19.9dp"
android:paddingLeft="10dp"
android:layout_marginTop="-20dp" />
<TextView
android:id="#+id/bottom"
android:textColor="#ff7e7777"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="63.3dp"
android:paddingLeft="50dp"
android:layout_gravity="left"
android:text="Note" />
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/date"
android:layout_marginLeft="250dp"
android:layout_marginRight="5dp" />
</LinearLayout>
In my main activity I tried the Btn.Click event but it only produces an error. And from what I've read in similar problems, their button was initialize in their Array Adapter but I'm using SimpleCursorAdapter because I'm fetching data from my sqlite database.
What should I do then? Please don't give me java codes because some them aren't applicable in xamarin studio since it's c#. Thanks.
You can't do it this way because you have a lot of same items in ListView with same ids
You must set OnClickListener to your button in your Adapter's getView() method like this
(this is java code for android studio, so it can differ from c# code, but gist is the same)
Button btn = (Button) convertView.findViewById(R.id.deleteMemo);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//here you go
}
});
Try something like this (If you don't have Fragments delete the view. below)
var _view = view.FindViewById<ListView>(Resource.Id.listView1);
if (_view.ChildCount > 0){
Button _button = (Button)_view.GetItemAtPosition(0).GetChildAt(0);
}
Because you have a lot of similar objects on a list this is the only way i think to access them,
Remember that item position is relative to the current visible items on the screen and you cant access items that are not visible
i'm very much a beginner with programming.. but i'm trying to develop a small android app using monodroid to store contacts in and call contacts from the address book.
Please forgive me if this is very simple but i have a text field and a button, both of which are in my Resources XML file and i want to be able to CLEAR the text in the textbox by clicking the button which will obviously be called 'Clear'.. all help is much appreciated as i'm looking forward to learning more.
Let's say you have the following layout, which I assume is similar to what you have already:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/TextField"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/Clear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Clear"/>
</LinearLayout>
Then in your activity's code you can do:
var clear = FindViewById<Button>(Resource.Id.Clear);
var textField = FindViewById<TextView>(Resource.Id.TextField);
clear.Click += (src, args) =>
{
textField.Text = "";
};
how about this?
Button ClearText=(Button) findViewById(R.id.ClearText);
ClearText.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
EditText textedit=(EditText) findViewById(R.id.textedit);
textedit.setText("");
}
});
clear must be registered as onclick handler for the button in the layout file like this
<ImageButton android:id="#+id/ClearText"
android:text="#string/ClearText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
**android:onClick="clear"**
android:src="#drawable/clear"
/>
I'm working on an application for the Android OS using Android Mono so I can program it in C#. All things are working well except for this one issue I am getting.
Basically, I have a sample code that changes the text of a button on every click. I tried to modify the sample code so that instead of changing the button, it changes the text of an xml textview object and, upon getting this error, I replaced it with an edittext object. I replaced it because it seemed common sense that editing an edittext would be easier than a textview.
Anywho, I got the same error at the same place. Whenever I try to change the textview.text or the edittext.text, the program freezes up and I get the error 'Unknown Member".
Here is the C# portion of the code:
Button ampButton = FindViewById<Button>(Resource.Id.CurrentButton);
ampButton.Click += delegate
{
SetContentView(Resource.Layout.AmpScreen);
Button ampButton2 = FindViewById<Button>(Resource.Id.CurrentButtonamp);
EditText ampData = FindViewById<EditText>(Resource.Id.ampdata);
ampButton2.Click += delegate
{
ampButton2.Text = string.Format("{0} clicks!", count2++);
ampData.Text = ampButton2.Text;
//string temp = Convert.ToString(count2) + " clicks!";
//ampData.Text=temp;
//count2++;
};
};
Here are the XML sections that are affected:
From the Main.xml:
<Button
android:id="#+id/CurrentButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Amp"
/>
From the AmpScreen.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView id="#+id/ampImage"
android:layout_width="50px"
android:layout_height="50px"
android:layout_gravity="center"
android:src="#drawable/amp"/>
<EditText id="#+id/ampdata"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading"/>
<Button
android:id="#+id/CurrentButtonamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Re-scan"
/>
<Button
android:id="#+id/homeButtonamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back"
/>
</LinearLayout>
Looks like a simple issue with your xml.
In your AmpScreen.xml on the EditText element:
id="#+id/ampdata"
should be:
android:id="#+id/ampdata"
UPDATE____
Logcat output http://pastie.org/2039452
My application is stopping in the debugger, and then crashing on this line, but it is strange because it has no error information just a green arrow like so...
Any insight on what this arrow means in general would be appreciated...
Here is LayoutStudentList
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<TextView
android:id="#+id/studentHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"
android:text="#string/StudentListHeader"
android:layout_alignParentTop="true"
/>
<EditText
android:id="#+id/studentSearch"
android:layout_width="fill_parent"
android:layout_below="#id/studentHeader"
android:padding="10dp"
android:textSize="12sp"
android:editable="true"
android:hint="#string/StudentFilterPlaceholder"
/>
<ListView
android:id="#+id/studentListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/studentSearch"
android:padding="10dp"
/>
</RelativeLayout>
The problem is almost definitely in my XML somewhere, as when I replace the layout contents with a single textview and set the text it works fine.
The problem is that the studentSearch EditText element in your layout file didn't specify a layout_height attribute. Once you add that in the problem should go away (I verified this locally as well). The error message and accompanying stacktrace would also be visible via the ADB logcat output:
I/dalvikvm( 2083): Ljava/lang/RuntimeException;: Binary XML file line #14: You must supply a layout_height attribute.
What does 'hanging' mean? Like, stopped in the debugger? Crashing?
Shouldn't that be setContentView(), not Set with a capital S? Maybe that's the problem.