Friday, August 24, 2018

Filter listview with checkbox, privious checked not retrive after filter listview

after filter list-view previous checked item result not get,just get filter result while when search-view set empty all checked item get.

    public void showResult() {
for (Contactmodel p : contactadapter.getBox()) {
            if (p.box) {
                name +=   p.getName()+" ";
                number +=  p.getContact()+",";
            }}
            if (number != "") {
                Intent intent = new Intent(getApplicationContext(), Setalert.class);
                intent.putExtra(key_phoneno, number);
                intent.putExtra(key_recipname, name);
                startActivity(intent);
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
        Toast.makeText(getApplication(),number,Toast.LENGTH_SHORT).show();

            } else {
                alerts(Viewcontacts.this, R.string.nocontactselected);
            }
    }

Monday, August 20, 2018

CKEDITOR doesn't submit data via ajax on first submit

My forms are not sending data to the server on the first submit when using CKEDITOR. If I click it once, it sends empty fields without my input. However, if I submit it a second time, it sends the inputted data to the server. So you need to submit it twice for data to be passed to the server.

I have CKEDITOR bundled with the BBCODE plugin.

jQuery Ajax

$('form#ajax').on('submit', function(){

    var that = $(this),
        url = that.attr('action'),
        type = that.attr('method'),
        data = {};

    that.find('[name]').each(function(index, value){
        var that = $(this),
            name = that.attr('name'),
            value = that.val();

        data[name] = value;
    });

    console.log(data.message); // Outputs on second submit

    $.ajax({
        url: url,
        type: type,
        data: data,
        success: function(response){

            //

        }
    });

    return false;
});

Form

{{ Form::open(array('action' => 'AppsController@sendApp', 'class' => 'app', 'id' => 'ajax')) }}

    
{{ Form::label('message', 'Application', array('style' => 'padding-top: 5px')) }} {{ Form::submit('Send Application', array('class' => 'btn btn-core btn-block submit', 'style' => 'margin-top: 5px')) }} {{ Form::close() }}

Sorry if the form syntax looks alien to you, it's Laravel Blade.

Recap

On first submit, the data sent to the server is empty. On the second submit, it is not.

Solved

try updating the CKEditor related fields, before performing Ajax Submit, like:

$('form#ajax').on('submit', function(){
    for ( instance in CKEDITOR.instances ) {
        CKEDITOR.instances[instance].updateElement();
    }
    //rest of your code

Sunday, August 19, 2018

Predicate that succeeds if two or more results are returned

How to implement rule1 that succeeds iff rule2 returns two or more results?

rule1(X) :-
    rule2(X, _).

How can I count the results, and then set a minimum for when to succeed?

Solved

How can I count the results, and then set a minimum for when it's true?

It is not clear what you mean by results. So I will make some guesses. A result might be:

A solution. For example, the goal member(X,[1,2,1]) has two solutions. Not three. In this case consider using either setof/3 or a similar predicate. In any case, you should first understand setof/3 before addressing the problem you have.

An answer. The goal member(X,[1,2,1]) has three answers. The goal member(X,[Y,Z]) has two answers, but infinitely many solutions.

So if you want to ensure that there are at least a certain number of answers, define:

at_least(Goal, N) :-
   \+ \+ call_nth(Goal, N).

with call_nth/2 defined in another SO-answer.

Note that the other SO-answers are not correct: They either do not terminate or produce unexpected instantiations.


you can use library(aggregate) to count solutions

:- use_module(library(aggregate)).

% it's useful to declare this for modularization
:- meta_predicate at_least(0, +).

at_least(Predicate, Minimum) :-
      aggregate_all(count, Predicate, N),
      N >= Minimum.

example:

?- at_least(member(_,[1,2,3]),3).
true.

?- at_least(member(_,[1,2,3]),4).
false.

edit here is a more efficient way, using SWI-Prolog facilities for global variables

at_least(P, N) :-
    nb_setval(at_least, 0),
    P,
    nb_getval(at_least, C),
    S is C + 1,
    ( S >= N, ! ; nb_setval(at_least, S), fail ).

with this definition, P is called just N times. (I introduce a service predicate m/2 that displays what it returns)

m(X, L) :- member(X, L), writeln(x:X).

?- at_least(m(X,[1,2,3]),2).
x:1
x:2
X = 2.

edit accounting for @false comment, I tried

 ?- call_nth(m(X,[1,2,3]),2).
x:1
x:2
X = 2 ;
x:3
false.

with call_nth from here.

From the practical point of view, I think nb_setval (vs nb_setarg) suffers the usual tradeoffs between global and local variables. I.e. for some task could be handly to know what's the limit hit to accept the condition. If this is not required, nb_setarg it's more clean.

Bottom line: the better way to do would clearly be using call_nth, with the 'trick' of double negation solving the undue variable instantiation.


Saturday, August 18, 2018

Cordova emulator not starting

I am trying to use the Android emulator to install an app on it.

Unfortunately the emulator is never starting up. I use the following command in my cordova project:

cordova emulate android

The last output I get from console is:

Waiting for emulator...

But the emulator does never start (I waited 45 minutes now).

The path variables are all correctly set and I can start the emulator using Eclipse or Android studio but not using the command from cordova.

Any hints?

Solved

If you can start the emulator through android studio, then as a work around start the emulator outside and run the command

cordova run android

It will deploy your app in the already running emulator.


Check emulator path settings https://cordova.apache.org/docs/en/4.0.0/guide_platforms_android_index.md.html If not able to execute then do : use the alternate shell interface:

$ /path/to/project/cordova/run --emulator

Instead of relying on whichever emulator is currently enabled within the SDK, you can refer to each by the names you supply:

$ /path/to/project/cordova/run --target=NAME

Check the documentation above and see whether your PC supports virtualization or not.


I was getting the same issue, I resolved it by:

Open Android device manager, click on window -> Android Virtual Device Manager

There you will see listing of all the Android Virtual Devices, if you see any device with repairable icon on it, just click on repair and then try. It works.


I had the same problem. Though cordova started the emulator, the command line kept on saying 'Waiting for emulator...' forever.

The trick is, before running the command:

cordova run android make sure you navigate into the android platform folder. That is, don't run the command from within the

/project folder

but instead from within

/project/platforms/android folder

That will launch your application in the Android emulator