last day (292 days later) » 

2:38 AM
0
A: How to get checked radio button and how to control only one radio button selected in list view

Leo ZhuYou could create a collection to store the check status of the radiobutton, and then load the collection when it is loaded in getView. like this : class YourAdapter : BaseAdapter,CompoundButton.IOnCheckedChangeListener { private Dictionary<int, bool> checkDictionary = new Dictionary<...

 
my item is a list
 
you mean your data is a list ?
Same thing, just change "int[] item" to your list,you could have a try
 
public MyAdapter(int[] value) how to do on here ?
 
this is the construction parameter of the Adapter that your activity instantiates, and it passes in your data, which is your list
 
it show error in MyAdapter...my have a return value
 
2:38 AM
What error was reported
 
this method must have a return type. << in MyAdapter
An object reference is required for the non-static field,method or property "XXX.checkDictionary"
 
Did you declare checkDictionary as I did in the sample code ?
 
private Dictionary<int, bool> checkDictionary = new Dictionary<int, bool>(); yes..i did
 
all the method and property are in the Adapter inside ,do you call the checkDictionary on some static method ?
You could update your Adapter and let me see where the problem might be
 
my code not able to post here..lol stackoverflow check too many code..
already edited on my question.
 
2:38 AM
You try it with getView() in my example, I could see you edit the getView above a few places in the wrong, a. blradio. Tag = position, it must set the position to lblradio. Tag to get the correctly position after checked ,b. lblradio. SetOnCheckedChangeListener (this);,let the Adapter to implement CompoundButton IOnCheckedChangeListener,c. in the OnCheckedChanged,finally, NotifyDataSetChanged() is called to refresh
 
..i follow yr way..still got error on it a) MyAdapter there hit method must have return type. b) lblradio.SetOnCheckedChangeListener(this); hit on "this", cannot convert from "XXX" to Android.Widget.CompoundButton.IOnCheckedChangeListener
 
I don't quite understand “ a) MyAdapter there hit method must have return type.” the error in b), you could "alt + Enter" to auto repair(choose "Make yourAdapter implement IOnCheckedChangeListener") or directly add like class StocktakeEditViewAdaptor : BaseAdapter<Model.FileRecord> ,CompoundButton.IOnCheckedChangeListener
you could explain a) more clearly
 
or u able to give me yr email..i show u my code
 
could you uploaded to the git ?
 
i think not able oh..privacy thing from company
 
2:38 AM
maybe you could show me your code here
 
ok
how to show u
class StocktakeEditViewAdaptor : BaseAdapter<Model.FileRecord>
{

Android.App.Activity context;
List<Model.FileRecord> items;
RadioButton lblradio;
public static string lineNo;
public static string barcode;
public static string qty;
private Dictionary<int, bool> checkDictionary = new Dictionary<int, bool>();
private Boolean userSelected = false;
List<View> createdview = new List<View>();
public Adapter(List<Model.FileRecord> items) //raplace your own data
{
for (int i = 0; i < items.Count(); i++)
 
Which constructor parameter you call when you instantiate the adapter ?is this public StocktakeEditViewAdaptor(Android.App.Activity context, List<Model.FileRecord> items) ?
I'll rework some of your code and you can try it
 
2:57 AM
ya
is public stocktakeeditviewAdaptor
 
when you new stocktakeeditviewAdaptor(),one parameter or two parameters?
 
u mean load the adaptor ?
public void loadList(string fileName)
{
List<Model.FileRecord> list = new List<Model.FileRecord>();
Model.FileRecord item = new Model.FileRecord();

list = GeneralFunc.GetFileRecord(fileName);

StocktakeEditViewAdaptor adaptor = new StocktakeEditViewAdaptor(this, list);

lvJournal.Adapter = adaptor;
}
this one is how i call the adaptor
 
ok
class StocktakeEditViewAdaptor : BaseAdapter<Model.FileRecord>, CompoundButton.IOnCheckedChangeListener
{

Android.App.Activity context;
List<Model.FileRecord> items;
RadioButton lblradio;
public static string lineNo;
public static string barcode;
public static string qty;
private Dictionary<int, bool> checkDictionary = new Dictionary<int, bool>();
private Boolean userSelected = false;
List<View> createdview = new List<View>();

public StocktakeEditViewAdaptor(Android.App.Activity context, List<Model.FileRecord> items)
you try to use the code to run
 
3:15 AM
still got one error
haha
lblradio.SetOnCheckedChangeListener(this);
in here
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace Inventory_Control_System
{
class StocktakeEditViewAdaptor : BaseAdapter<Model.FileRecord>
{

Android.App.Activity context;
List<Model.FileRecord> items;
RadioButton lblradio;
public static string lineNo;
public static string barcode;
public static string qty;
private Dictionary<int, bool> checkDictionary = new Dictionary<int, bool>();
here my full code
 
class StocktakeEditViewAdaptor : BaseAdapter<Model.FileRecord> this line
change to
class StocktakeEditViewAdaptor : BaseAdapter<Model.FileRecord>, CompoundButton.IOnCheckedChangeListener
 
nice
i try run
and u know how to save file to sd card ?
now i save my file to internal storage
 
you could search it ,a lot of sample
Let me see if I have it ready
 
ok
because i use externalstoragedir
cant get the sd card path
 
could it run ?
diptimayapatra.wordpress.com/2013/07/10/… you could look at the link , writeTextFile() is save file to sd card
I'm going out for lunch now. I'll contact you this afternoon if you have any questions
 
3:27 AM
okay
thank a lot
lblradio.Tag u change it to position
lblradio.Tag = position;
then how to get select which record ah
haha
if use position..i able to select only one radio button
i try this..
var test = Android.OS.Environment.ExternalStorageDirectory.Path;
the test = /storage/emulated/0
 
4:20 AM
you get the position then you could do manything you want
 
but let say
first will show possition 0 - 10
if i search record 9
will only show record no 9
then the position become 0 ady
 
5:06 AM
your record could use items[(int)buttonView.Tag].FileRecord_ID + ":" + items[(int)buttonView.Tag].ST_Barcode + ":" + items[(int)buttonView.Tag].ST_Qty in OnCheckedChanged
 
5:24 AM
ok..i try
 
5:34 AM
yeah
can get the selected data
https://diptimayapatra.wordpress.com/2013/07/10/xamarin-write-file-to-sd-card-in-android/
i follow yr shared link
got problem
it save file to internal storage
not sd card
 
Android.OS.Environment.ExternalStorageDirectory.Path is sd card path =.=
 
haha
i fail to create file to here
/storage/emulated/0
 
Do you have the appropriate permissions
 
yeah
the application inside my device ady grant to storage
 
6:21 AM
Was there an error writing to the file?
 
6:37 AM
yeah
permission denied
lol
permission denied to access
/storage/emulated/0
 
6:55 AM
Leo..if radio button change to checkbox
can multiple record
how ya ?
 
7:09 AM
ops..checkbox can check and uncheck
haha
 
Yes, because your checked state is checked, so your checkbox is checked
 
haha
ok
maybe can help me on sd card tat one ?
still not able to create a file to certain location in sd card :(
 
This kind of storing state with collections applies to many scenarios
I tested it, and it's the same error. Maybe you can try putting it in the file directory of your application
var sdCardPath = Environment.ExternalStorageDirectory.Path;
change to
var sdCardPath = Android.App.Application.Context.GetExternalFilesDir(null).ToString();
 
ok
i test test
this one is which location ya ?
Android.App.Application.Context.GetExternalFilesDir(null).ToString();
 
"/storage/emulated/0/Android/data/pakeage name/files"
you can have a try
 
7:21 AM
ya
put to my program file
lol
why cant access to sd card ah
i am sad
 
There may be permission changes after 6.0,I haven't looked very carefully
 
omg
:(
wait
Android.App.Application.Context.GetExternalFilesDir(null).ToString();
is store in my package
if my package in sd card
how ?
haha
if my program build there select prefer external
 
7:38 AM
Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.ExternalStorageDirectory) where the application can place persistent files it owns. so it is also in external
 
haha
not understand
so need use absolute path ?
 
no,It's just an explanation of
Android.App.Application.Context.GetExternalFilesDir
 
7:54 AM
haha
i see
:(
i though got solution
public static Boolean checkExternalMedia()
        {
            //string loc = "/mnt/sdcard/Android/data/Setting";
            //File path = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "data");   //GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            File path = new File(configureFile);
            String state = Environment.GetExternalStorageState(path);
            if (state.Equals(Environment.MediaMounted) && !state.Equals(Environment.MediaMountedReadOnly))
this one use for what ya
check externalMedia
 
8:06 AM
it determines if an SD Card is available
I found the reason, after 6.0 need to manually request Storage permissions
I used a nuget package that requested permissions and it ran successfully
the nuget pakeage :Plugin.Permissions
 protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.activity_main);
        Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
}
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Plugin.Permissions.Abstractions.Permission.Storage);
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Plugin.Permissions.Abstractions.Permission.Storage))
{
Toast.MakeText(this, "1111" + myTextView.GetEstimatedLength(), ToastLength.Short).Show();
}

var results = await CrossPermissions.Current.RequestPermissionsAsync(Plugin.Permissions.Abstractions.Permission.Storage);
you could look at the document :github.com/jamesmontemagno/PermissionsPlugin
 
walao
haha
nice
i try ya
 
yeah,please give me a mark ,thank you ~~
 
love u la
hahaha
how to give u mark ?
lol
how to use the permission ya
 
You download the nuget package, then initialize it in OnCreate using my example above, and finally add the code from my example above before you need to start the sdcard operation
Or you can follow the link I gave in the operation
 
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.StockTakeSelectedBrand);
        //Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this,bundle);
on create is savedInstanceState
not bund;e
 
8:21 AM
yes,the same ,you changet to savedInstanceState
 
haha
ok
then copy yr code ya ?
 
its only a parameter names
yes
You can delete Toast if you don't use it, and you can change the file name to your own
 
error
the "await" operator can only be used within an async method
 
you add async to your method
like this : public async void Method(string s)
 
ok
done
try run
will prompt out to ask
access to sd card ah ?
 
8:35 AM
still have the error?
 
trying
awhile
haha
lol
i ady granted
 
success?
Finally at stackoverflow.com/questions/54211937/…, please give me a mark in this issure, thank you~haha
 
sure
haven success
haha
the file still store to internal storage
 
8:51 AM
I'm also puzzled by this, it shows that the directory is internal storage, but the address provided by the Api is sdcard
 
lol
i am sad
fantastic right
public async void writeToSDFile()
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Plugin.Permissions.Abstractions.Permission.Storage);
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Plugin.Permissions.Abstractions.Permission.Storage))
{
//Toast.MakeText(this, "1111" + myTextView.GetEstimatedLength(), ToastLength.Short).Show();
}

var results = await CrossPermissions.Current.RequestPermissionsAsync(Plugin.Permissions.Abstractions.Permission.Storage);
my code like this
same like u show me
 
yes
docs.microsoft.com/en-us/xamarin/android/platform/files/… .You can look at the official document, there are a lot of file path, maybe you can find what you really want
 
oh
this one
i read ady
 
He also said the“ Environment. ExternalStorageDirectory. Path” is a external storage
 
ya
:(
Android.Content.Context.GetExternalFilesDir(string type)
what is tat
 
9:03 AM
For devices that have multiple external storage partitions, each partition will have a directory that is intended for private files. The method Android.Content.Context.GetExternalFilesDirs(string type) will return an array of Java.IO.Files. Each object will represent a private application-specific directory on all shared/external storage devices where the application can place the files it owns.
 
haha
i trying everything
 
haha
 
            var sdCardPath = Android.OS.Environment.DataDirectory.Path;
            var sdCardPath1 = Android.OS.Environment.DirectoryDcim;
            //var sdCardPath2 = Android.OS.Environment.GetExternalStoragePublicDirectory.sdCardPath;
haiz
see what path return
sdCardPath = return /data
sdCardPath1 = return DCIM
 
yeah
 
how ah
cant save file to sd card
 
9:15 AM
It could also be a display error, which is actually in sdcard
 
haha
nani
hehe
 
I just saw someone say it's inverted
 
maybe i restart device
let say
var sdCardPath = Environment.ExternalStorageDirectory.Path;
able to save in sd card
if i create one folder in sd card
i want store to tat folder
how ya ?
 
Read it out and then write it in the new path
 
mean i need write to Environment.ExternalStorageDirectory.Path;
then read the file and move it to my folder ?
i found something
in developer option there
below got one option...force allow apps on external
 
9:25 AM
you could try it
 
today is friday
go back liao
 
Well, have a nice weekend
 
weekend also need work
i tomorrow continue
 
haha
where are you from ?
 
Singapore
where u from ?
 
9:36 AM
China
 
nice
nice to meet u
 
haha,nice to meet u ,too
 
this room can keep ?
haha
 
i dont know,but it should still work next time
 
nice
any thing i can ask u ma
u is my 师傅
 
9:40 AM
no problem
 
i use adb shell
storage/emulated/
cant access
 
It could be a permission issue
You try administrator identity access
 
nvm
i pull from adb
to my local
look like everything in /0 is my internal storage thing
 
This is awkward
 
i am sad
haha
give up today
maybe tomorrow can do
how can i contact u ?
other then here
 
9:48 AM
you could post issure @me
I'm off duty. See you next week
 

  last day (292 days later) »