每当我从一个活动导航到另一个活动时,我的android应用程序都会保持滞后。我有一个想法,它可能是大图像的原因。关于这一点,我决定使用Picasso,然后切换到Glide以有效加载和缩放图像,以避免滞后和性能下降。但似乎这些包装都没有为我顺利运作。
因为我有一个想法,它可能是我的一些图像,我决定用大小(200字节)的图标替换我的所有图像,当我从活动移动到另一个时,应用程序仍然滞后。当我单击左侧的导航抽屉时,它会滞后几秒钟,然后完全向左绘制并显示数据。显然,当我不执行任何数据通话时,应用程序并不会滞后。
查看我的日志cat,了解我的应用程序是如何运行的。有人请帮我解决这个问题,因为我目前不知道问题的来源。
我有3项活动。
1)主启动器当前没有数据。它只有一个工具栏,左侧是导航抽屉
2)第二个活动从互联网上提取图像和文字。
3)显示联系人的图像(circleImageView)和文本(名称)
登录主启动器
[Mono] Assembly Ref addref Xamarin.Android.Support.Fragment[0x7e2e0160] -> System.Core[0x7efed490]: 4
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_get_array_length'.
[Mono] Probing 'java_interop_jnienv_get_array_length'.
[Mono] Found as 'java_interop_jnienv_get_array_length'.
[Mono] Assembly Ref addref peaceApp.Droid[0x7c7bc640] -> Xamarin.Android.Support.v7.RecyclerView[0x7e7c8678]: 2
[Mono] Assembly Ref addref Xamarin.Android.Support.v7.RecyclerView[0x7e7c8678] -> Xamarin.Android.Support.Compat[0x7ddf0878]: 3
[Mono] Assembly Ref addref peaceApp.Droid[0x7c7bc640] -> mscorlib[0x737bb290]: 48
[Mono] Assembly Ref addref peaceApp.Droid[0x7c7bc640] -> Xamarin.Android.Support.Core.UI[0x7e14d710]: 3
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_new_string'.
[Mono] Probing 'java_interop_jnienv_new_string'.
[Mono] Found as 'java_interop_jnienv_new_string'.
[Mono] Assembly Ref addref peaceApp.Droid[0x7c7bc640] -> Xamarin.Android.Support.Design[0x7e27a2d0]: 2
[Mono] Assembly Ref addref peaceApp.Droid[0x7c7bc640] -> Xamarin.Android.Support.Fragment[0x7e2e0160]: 3
[dalvikvm-heap] Grow heap (frag case) to 28.817MB for 9000016-byte allocation
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_object_method_a'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_object_method_a'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_object_method_a'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_nonvirtual_object_method'.
[Mono] Probing 'java_interop_jnienv_call_nonvirtual_object_method'.
[Mono] Found as 'java_interop_jnienv_call_nonvirtual_object_method'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_void_method_a'.
[Mono] Probing 'java_interop_jnienv_call_void_method_a'.
[Mono] Found as 'java_interop_jnienv_call_void_method_a'.
[Mono] Assembly Ref addref Xamarin.Android.Support.Design[0x7e27a2d0] -> Xamarin.Android.Support.Core.UI[0x7e14d710]: 4
[Adreno-EGL] <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
[Adreno-EGL] OpenGL ES Shader Compiler Version: E031.24.00.07
[Adreno-EGL] Build Date: 01/22/14 Wed
[Adreno-EGL] Local Branch: base_au149_adreno_au169_patches
[Adreno-EGL] Remote Branch:
[Adreno-EGL] Local Patches:
[Adreno-EGL] Reconstruct Branch:
[OpenGLRenderer] Enabling debug mode 0
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
第二项活动
[Mono] Unloading image System.Reflection.dll [0x82696200].
[Mono] Image addref System.Reflection[0x82695838] -> System.Reflection.dll[0x7ef44a48]: 5
[Mono] Config attempting to parse: 'System.Reflection.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Reflection/System.Reflection.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Reflection[0x7ef45668]: 3
[Mono] Unloading image System.Linq.dll [0x82696200].
[Mono] Image addref System.Linq[0x82696048] -> System.Linq.dll[0x7eff61a0]: 5
[Mono] Config attempting to parse: 'System.Linq.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Linq/System.Linq.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Linq[0x7efec330]: 3
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Reflection.Extensions[0x7f01cad0]: 3
[Mono] Image addref System.ComponentModel.TypeConverter[0x826daa38] -> System.ComponentModel.TypeConverter.dll[0x826d7e20]: 2
[Mono] Prepared to set up assembly 'System.ComponentModel.TypeConverter' (System.ComponentModel.TypeConverter.dll)
[Mono] Assembly System.ComponentModel.TypeConverter[0x826daa38] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.ComponentModel.TypeConverter.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.ComponentModel.TypeConverter.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.ComponentModel.TypeConverter.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.ComponentModel.TypeConverter.dll.so" not found
[Mono] Config attempting to parse: 'System.ComponentModel.TypeConverter.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.ComponentModel.TypeConverter/System.ComponentModel.TypeConverter.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.ComponentModel.TypeConverter[0x826daa38]: 2
Loaded assembly: System.ComponentModel.TypeConverter.dll [External]
[Mono] Assembly Ref addref System.ComponentModel.TypeConverter[0x826daa38] -> System[0x82665978]: 4
[Mono] Assembly Ref addref System.ObjectModel[0x82664640] -> mscorlib[0x737bb290]: 56
[Mono] Image addref System.Runtime.Serialization[0x83e5cb80] -> System.Runtime.Serialization.dll[0x83e457f0]: 2
[Mono] Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
[Mono] Assembly System.Runtime.Serialization[0x83e5cb80] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Runtime.Serialization.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Runtime.Serialization.dll.so" not found
[Mono] Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
[Mono] Assembly Ref addref System.Runtime.Serialization.Primitives[0x83acfff8] -> System.Runtime.Serialization[0x83e5cb80]: 2
[Mono] Assembly Ref addref System.Runtime.Serialization[0x83e5cb80] -> mscorlib[0x737bb290]: 57
Loaded assembly: System.Runtime.Serialization.dll [External]
[Mono] Assembly Ref addref System.Core[0x7efed490] -> System[0x82665978]: 5
[Mono] Image addref System.Linq.Expressions[0x83e78c00] -> System.Linq.Expressions.dll[0x83e94518]: 2
[Mono] Prepared to set up assembly 'System.Linq.Expressions' (System.Linq.Expressions.dll)
[Mono] Assembly System.Linq.Expressions[0x83e78c00] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Linq.Expressions.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Linq.Expressions.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Linq.Expressions.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Linq.Expressions.dll.so" not found
[Mono] Config attempting to parse: 'System.Linq.Expressions.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Linq.Expressions/System.Linq.Expressions.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Linq.Expressions[0x83e78c00]: 2
[Mono] Assembly Ref addref System.Linq.Expressions[0x83e78c00] -> System.Core[0x7efed490]: 7
Loaded assembly: System.Linq.Expressions.dll [External]
Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
[Mono] Image addref System.Reflection.Primitives[0x83fe3578] -> System.Reflection.Primitives.dll[0x83fe2f88]: 2
[Mono] Prepared to set up assembly 'System.Reflection.Primitives' (System.Reflection.Primitives.dll)
[Mono] Assembly System.Reflection.Primitives[0x83fe3578] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Reflection.Primitives.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Reflection.Primitives.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Reflection.Primitives.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Reflection.Primitives.dll.so" not found
[Mono] Config attempting to parse: 'System.Reflection.Primitives.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Reflection.Primitives/System.Reflection.Primitives.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Reflection.Primitives[0x83fe3578]: 2
Loaded assembly: System.Reflection.Primitives.dll [External]
[Mono] Assembly Ref addref System.Reflection.Primitives[0x83fe3578] -> mscorlib[0x737bb290]: 58
[Mono] Assembly Ref addref System.Collections[0x7ef3daf8] -> System.Core[0x7efed490]: 8
[Choreographer] Skipped 87 frames! The application may be doing too much work on its main thread.
[Mono] Assembly Ref addref peaceApp.Droid[0x7c7bc640] -> Glide[0x7da25b40]: 2
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[ViewRootImpl] sendUserActionEvent() mView == null
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
第3次活动
Loaded assembly: System.Numerics.dll [External]
[Mono] Unloading image System.Reflection.dll [0x82696200].
[Mono] Image addref System.Reflection[0x82695838] -> System.Reflection.dll[0x7ef44a48]: 5
[Mono] Config attempting to parse: 'System.Reflection.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Reflection/System.Reflection.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Reflection[0x7ef45668]: 3
[Mono] Unloading image System.Linq.dll [0x82696200].
[Mono] Image addref System.Linq[0x82696048] -> System.Linq.dll[0x7eff61a0]: 5
[Mono] Config attempting to parse: 'System.Linq.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Linq/System.Linq.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Linq[0x7efec330]: 3
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Reflection.Extensions[0x7f01cad0]: 3
[Mono] Image addref System.ComponentModel.TypeConverter[0x826daa38] -> System.ComponentModel.TypeConverter.dll[0x826d7e20]: 2
[Mono] Prepared to set up assembly 'System.ComponentModel.TypeConverter' (System.ComponentModel.TypeConverter.dll)
[Mono] Assembly System.ComponentModel.TypeConverter[0x826daa38] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.ComponentModel.TypeConverter.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.ComponentModel.TypeConverter.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.ComponentModel.TypeConverter.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.ComponentModel.TypeConverter.dll.so" not found
[Mono] Config attempting to parse: 'System.ComponentModel.TypeConverter.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.ComponentModel.TypeConverter/System.ComponentModel.TypeConverter.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.ComponentModel.TypeConverter[0x826daa38]: 2
Loaded assembly: System.ComponentModel.TypeConverter.dll [External]
[Mono] Assembly Ref addref System.ComponentModel.TypeConverter[0x826daa38] -> System[0x82665978]: 4
[Mono] Assembly Ref addref System.ObjectModel[0x82664640] -> mscorlib[0x737bb290]: 56
[Mono] Image addref System.Runtime.Serialization[0x83e5cb80] -> System.Runtime.Serialization.dll[0x83e457f0]: 2
[Mono] Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
[Mono] Assembly System.Runtime.Serialization[0x83e5cb80] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Runtime.Serialization.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Runtime.Serialization.dll.so" not found
[Mono] Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
[Mono] Assembly Ref addref System.Runtime.Serialization.Primitives[0x83acfff8] -> System.Runtime.Serialization[0x83e5cb80]: 2
[Mono] Assembly Ref addref System.Runtime.Serialization[0x83e5cb80] -> mscorlib[0x737bb290]: 57
Loaded assembly: System.Runtime.Serialization.dll [External]
[Mono] Assembly Ref addref System.Core[0x7efed490] -> System[0x82665978]: 5
[Mono] Image addref System.Linq.Expressions[0x83e78c00] -> System.Linq.Expressions.dll[0x83e94518]: 2
[Mono] Prepared to set up assembly 'System.Linq.Expressions' (System.Linq.Expressions.dll)
[Mono] Assembly System.Linq.Expressions[0x83e78c00] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Linq.Expressions.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Linq.Expressions.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Linq.Expressions.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Linq.Expressions.dll.so" not found
[Mono] Config attempting to parse: 'System.Linq.Expressions.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Linq.Expressions/System.Linq.Expressions.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Linq.Expressions[0x83e78c00]: 2
[Mono] Assembly Ref addref System.Linq.Expressions[0x83e78c00] -> System.Core[0x7efed490]: 7
Loaded assembly: System.Linq.Expressions.dll [External]
Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
[Mono] Image addref System.Reflection.Primitives[0x83fe3578] -> System.Reflection.Primitives.dll[0x83fe2f88]: 2
[Mono] Prepared to set up assembly 'System.Reflection.Primitives' (System.Reflection.Primitives.dll)
[Mono] Assembly System.Reflection.Primitives[0x83fe3578] added to domain RootDomain, ref_count=1
[Mono] AOT: image 'System.Reflection.Primitives.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Reflection.Primitives.dll.so" not found
[Mono] AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Reflection.Primitives.dll.so' not found: dlopen failed: library "/data/app-lib/com.companyname.peaceapp.peaceapp-25/libaot-System.Reflection.Primitives.dll.so" not found
[Mono] Config attempting to parse: 'System.Reflection.Primitives.dll.config'.
[Mono] Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Reflection.Primitives/System.Reflection.Primitives.config'.
[Mono] Assembly Ref addref Newtonsoft.Json[0x7db5a818] -> System.Reflection.Primitives[0x83fe3578]: 2
Loaded assembly: System.Reflection.Primitives.dll [External]
[Mono] Assembly Ref addref System.Reflection.Primitives[0x83fe3578] -> mscorlib[0x737bb290]: 58
[Mono] Assembly Ref addref System.Collections[0x7ef3daf8] -> System.Core[0x7efed490]: 8
[Choreographer] Skipped 87 frames! The application may be doing too much work on its main thread.
[Mono] Assembly Ref addref peaceApp.Droid[0x7c7bc640] -> Glide[0x7da25b40]: 2
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[ViewRootImpl] sendUserActionEvent() mView == null
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[Mono] GC_TAR_BRIDGE bridges 48 objects 78 opaque 171 colors 48 colors-bridged 48 colors-visible 48 xref 16 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.07ms tarjan 0.30ms scc-setup 0.04ms gather-xref 0.00ms xref-setup 0.00ms cleanup 0.03ms
[Mono] GC_BRIDGE: Complete, was running for 22.76ms
[Mono] GC_MAJOR: (user request) time 3.58ms, stw 4.17ms los size: 1024K in use: 43K
[Mono] GC_MAJOR_SWEEP: major size: 928K in use: 218K
Thread started: #3
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[Mono] GC_TAR_BRIDGE bridges 121 objects 176 opaque 339 colors 121 colors-bridged 121 colors-visible 121 xref 40 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.06ms tarjan 0.25ms scc-setup 0.07ms gather-xref 0.01ms xref-setup 0.02ms cleanup 0.06ms
[Mono] GC_BRIDGE: Complete, was running for 29.28ms
[Mono] GC_MAJOR: (user request) time 2.82ms, stw 3.37ms los size: 1024K in use: 43K
[Mono] GC_MAJOR_SWEEP: major size: 928K in use: 255K
Thread started: #4
[ProgressBar] updateDrawableBounds: left = 0
[ProgressBar] updateDrawableBounds: top = 0
[ProgressBar] updateDrawableBounds: right = 144
[ProgressBar] updateDrawableBounds: bottom = 144
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[ViewRootImpl] sendUserActionEvent() mView == null
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[RecyclerView] No adapter attached; skipping layout
[Mono] GC_TAR_BRIDGE bridges 143 objects 224 opaque 508 colors 143 colors-bridged 143 colors-visible 143 xref 55 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.06ms tarjan 0.24ms scc-setup 0.08ms gather-xref 0.01ms xref-setup 0.00ms cleanup 0.05ms
[Mono] GC_BRIDGE: Complete, was running for 28.35ms
[Mono] GC_MAJOR_SWEEP: major size: 976K in use: 314K
[Mono] GC_MAJOR: (user request) time 3.44ms, stw 3.78ms los size: 1024K in use: 43K
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_boolean_method_a'.
[Mono] Probing 'java_interop_jnienv_call_boolean_method_a'.
[Mono] Found as 'java_interop_jnienv_call_boolean_method_a'.
[ProgressBar] updateDrawableBounds: left = 72
[ProgressBar] updateDrawableBounds: top = 0
[ProgressBar] updateDrawableBounds: right = 72
[ProgressBar] updateDrawableBounds: bottom = 0
第二项活动
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity2);
LoadData();
rv = FindViewById<RecyclerView>(Resource.Id.recyclerView);
rv.SetLayoutManager(new LinearLayoutManager(this));
}
private void changeState(object sender, EventArgs e)
{
Toast.MakeText(this, "Action selected: ",
ToastLength.Short).Show();
}
private void LoadData()
{
StringBuilder strBuilder = new StringBuilder(Rss_to_json);
strBuilder.Append(URL from internet);
new LoadDataAsync(this).Execute(strBuilder.ToString());
}
class LoadDataAsync : AsyncTask<string, string, string>
{
MainActivity mainActivity;
ProgressDialog mDialog;
public LoadDataAsync(MainActivity mainActivity){
this.mainActivity = mainActivity;
}
protected override void OnPreExecute(){
mDialog = new ProgressDialog(mainActivity);
mDialog.Window.SetType(Android.Views.WindowManagerTypes.SystemAlert);
mDialog.SetMessage("Please Wait.......");
mDialog.Show();
}
protected override string RunInBackground(params string[] @params)
{
string result = new HTTPDataHandler().GetHTTPData(@params[0]);
return result;
}
protected override void OnPostExecute(string result){
RssObject data = JsonConvert.DeserializeObject<RssObject>(result);
mDialog.Dismiss();
MyAdapter adapter = new MyAdapter(data, mainActivity);
mainActivity.rv.SetAdapter(adapter);
adapter.NotifyDataSetChanged();
}
}
private void login_User(object sender, EventArgs e)
{
Intent intent = new Intent(this, typeof(LoginActivity));
this.StartActivity(intent);
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
Toast.MakeText(this, "Action selected: " + item.TitleFormatted,
ToastLength.Short).Show();
switch (item.ItemId)
{
case Android.Resource.Id.Home:
mDrawerLayout.OpenDrawer((int)GravityFlags.Left);
return true;
case Resource.Id.loginUser:
Intent user = new Intent(this, typeof(LoginActivity));
this.StartActivity(user);
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.main_menu, menu);
return base.OnCreateOptionsMenu(menu);
}
private void SetUpDrawerContent(NavigationView navigationView)
{
navigationView.NavigationItemSelected += (object sender, NavigationView.NavigationItemSelectedEventArgs e) =>
{
int id = e.MenuItem.ItemId;
switch(id){
case Resource.Id.activity2:
Intent intent = new Intent(this, typeof(activity2));
this.StartActivity(intent);
GC.Collect();
break;
case Resource.Id.activity3:
Intent photos = new Intent(this, typeof(activity3));
this.StartActivity(photos);
GC.Collect();
break;
}
e.MenuItem.SetChecked(true);
mDrawerLayout.CloseDrawers();
};
}
}
第3次活动
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity3);
this.refreshAll();
FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
fab.Click += delegate {
LayoutInflater eInflater = LayoutInflater.From(this);
View mView = eInflater.Inflate(Resource.Layout.PeaceHeroDialog, null);
Android.Support.V7.App.AlertDialog.Builder alertDialogBuilder = new Android.Support.V7.App.AlertDialog.Builder(this);
alertDialogBuilder.SetView(mView);
alertDialogBuilder.SetCancelable(false)
.SetPositiveButton("Save", async delegate
{
//save details into firebase
var firebase = new FirebaseClient(FirebaseUrl);
var item = await firebase.Child("Table").PostAsync<someArray>(add);
await RefreshData();
})
.SetNegativeButton("Cancel", delegate
{
alertDialogBuilder.Dispose();
});
Android.Support.V7.App.AlertDialog alertDialogAndroid = alertDialogBuilder.Create();
alertDialogAndroid.Show();
};
}
//refresh data
private async void refreshAll(){
await RefreshData();
}
private async Task RefreshData()
{
circular_progress.Visibility = ViewStates.Visible;
rv.Visibility = ViewStates.Invisible;
var firebase = new FirebaseClient(FirebaseUrl);
var items = await firebase.Child("table").OnceAsync<something>();
itemsToBeAdded.Clear();
refreshAdapter = null;
foreach (var item in items)
{
//code to fetch data from firebase
}
refreshAdapter = new PeaceHeroAdapter(itemToBeAdded, this );
rv.SetLayoutManager(new LinearLayoutManager(this));
rv.SetItemAnimator(new DefaultItemAnimator());
rv.SetAdapter(refreshAdapter);
refreshAdapter.NotifyDataSetChanged();
circular_progress.Visibility = ViewStates.Invisible;
rv.Visibility = ViewStates.Visible;
}
}