Jamisonhobertmaxine's Profile

165
Points

Questions
31

Answers
40

  • First you need condition like this for your UI in your onBindViewHolder method

    if (mSelectedItem == position) {         holder.radioButton.setChecked(true);     } else {         holder.radioButton.setChecked(false);     } 

    Then change your radio button listener like this

    holder.radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {         @Override         public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {             if (isChecked) {                 mSelectedItem = position;             } else {                 mSelectedItem = -1;             }             notifyDataSetChanged();         }     }); 

    try this i hope your problem will solve.

    • 313 views
    • 1 answers
    • 0 votes
  • Rather than using the downloadURL from w3schools you might wish to consider the fetch api, especially for instances where you need to negotiate CORS requests. In the code below the XML file was simply stored in the same directory as the HTML page and the data retrieved using fetch. Bizarrely however this new API, designed to replace the abused XMLHttpRequest, has no native methods for returning XML data directly so an addition step is required where the response data is parsed through the DOMParser before further processing.

    <!doctype html> <html lang='en'>     <head>         <meta charset='utf-8' />         <title>Google Maps: read XML file...</title>         <style>             #map{                 width:800px;                 height:600px;                 float:none;                 margin:auto;             }         </style>         <script>             function initMap(){                 var map;                                  const addmarker=( latlng, title, config={} )=>{                     let options={                         position:latlng,                         title:title,                         map:map                     };                     options=Object.assign( options, config );                                          let marker=new google.maps.Marker( options );                                          google.maps.event.addListener( marker, 'click', function(e){                         console.info( this )                     }.bind( marker ));                                          return marker;                 };                                  const attrib=(n,a)=>{                     return n.getAttribute(a);                 };                                                   fetch( 'mapmarkers2.xml' )                     .then( r=>{ return r.text() })                     .then( str => ( new window.DOMParser() ).parseFromString( str, 'text/xml' ) )                     .then( xml=>{                         let col=xml.documentElement.getElementsByTagName('marker');                                                  let options = {                             zoom: 12,                             center: new google.maps.LatLng( -33.853985, 151.099404 ),                         };                         map = new google.maps.Map( document.getElementById('map'), options );                                                  Array.from( col ).forEach( mkr=>{                             let id=attrib(mkr,'id');                             let name=attrib(mkr,'name');                             let address=attrib(mkr,'address');                             let type=attrib(mkr,'type');                             let lat=attrib(mkr,'lat');                             let lng=attrib(mkr,'lng');                              let config={                                 'id':id,                                 'name':name,                                 'address':address,                                 'type':type                             };                                                          addmarker( new google.maps.LatLng(lat,lng), name, config  );                         });                     })             }         </script>         <script async defer src='//maps.googleapis.com/maps/api/js?key=XXXYYYZZZ&callback=initMap'></script>     </head>     <body>         <div id='map'></div>     </body> </html> 
    • 336 views
    • 1 answers
    • 0 votes
  • Scenario #1: You accidentially re-deployed from the command line while tomcat was already running.

    Short Answer: Stop Tomcat, delete target folder, mvn package, then re-deploy


    Scenario #2: request.getRequestDispatcher(“MIS_SPELLED_FILE_NAME.jsp”)

    Short Answer: Check file name spelling, make sure case is correct.


    Scenario #3: Class Not Found Exceptions (Answer put here because: Question# 17982240 ) (java.lang.ClassNotFoundException for servlet in tomcat with eclipse ) (was marked as duplicate and directed me here )

    Short Answer #3.1: web.xml has wrong package path in servlet-class tag.

    Short Answer #3.2: java file has wrong import statement.


    Below is further details for Scenario #1:


    1: Stop Tomcat

    • Option 1: Via CTRL+C in terminal.
    • Option 2: (terminal closed while tomcat still running)
    • ———— 2.1: press:Windows+R –> type:”services.msc
    • ———— 2.2: Find “Apache Tomcat #.# Tomcat#” in Name column of list.
    • ———— 2.3: Right Click –> “stop

    2: Delete the “target” folder. (mvn clean will not help you here)

    3: mvn package

    4: YOUR_DEPLOYMENT_COMMAND_HERE

    (Mine: java -jar target/dependency/webapp-runner.jar –port 5190 target/*.war )

    Full Back Story:


    Accidentially opened a new git-bash window and tried to deploy a .war file for my heroku project via:

    java -jar target/dependency/webapp-runner.jar –port 5190 target/*.war

    After a failure to deploy, I realized I had two git-bash windows open, and had not used CTLR+C to stop the previous deployment.

    I was met with:

    HTTP Status 404 – Not Found Type Status Report

    Message /if-student-test.jsp

    Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    Apache Tomcat/8.5.31

    Below is further details for Scenario #3:


    SCENARIO 3.1: The servlet-class package path is wrong in your web.xml file.

    It should MATCH the package statement at top of your java servlet class.

    File: my_stuff/MyClass.java:

       package my_stuff; 

    File: PRJ_ROOT/src/main/webapp/WEB-INF/web.xml

       <servlet-class>    my_stuff.MyClass    </servlet-class> 

    SCENARIO 3.2:

    You put the wrong “package” statement at top of your myClass.java file.

    For example:

    File is in: “/my_stuff” folder

    You mistakenly write:

    package com.my_stuff 

    This is tricky because:

    1: The maven build (mvn package) will not report any errors here.

    2: servlet-class line in web.xml can have CORRECT package path. E.g:

    <servlet-class> my_stuff.MyClass </servlet-class> 

    Stack Used: Notepad++ + GitBash + Maven + Heroku Web App Runner + Tomcat9 + Windows10:

    • 614 views
    • 11 answers
    • 0 votes
  • Scriban does support nested looping. I’ve updated your code to show how you would do this.

    var bodyTextSub = @"{{ for service in services }}  ServiceName: {{ service.key }} {{$counter = 0}} SubServices: {{ for subService in service.value }}{{ if $counter > 0; `,` ; end ; $counter = $counter + 1 ;}}{{ subService }}{{ end }} {{ end }}";  var subServiceList = new List<string> {     "PingSubService",     "UrlSubService" };  var serviceDictionary = new Dictionary<string, List<string>>() {     {"emailContent", subServiceList},     {"mailContent", subServiceList} };  var template2 = Template.Parse(bodyTextSub); var result2 = template2.Render(new {services = serviceDictionary}); Console.WriteLine(result2.ToString()); 

    This will result in the following output:

    ServiceName: emailContent  SubServices: PingSubService, UrlSubService   ServiceName: mailContent  SubServices: PingSubService, UrlSubService 
    • 325 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    Your query is not correct. First you miss the alias u of the users table so the second row must look like:

    FROM users u

    Second, in the the fourth row you accidently wrote u.id = cph.id, but you want to match with the userId, not the cancelPaymentHistory.id. Additionally you miss the alias for the cancelPaymentHistory table. So the correct fourth line must look like:

    JOIN cancelPaymentHistory cph ON u.id = cph.userId

    The whole query would look like:

    SELECT u.id as userId,ph.bookingId as paymentHistoryBooking,cph.bookingId as CancelBookingId,ub.bookingId as usrBooking  FROM users u JOIN paymentHistory ph ON u.id=ph.userId JOIN cancelPaymentHistory cph ON u.id=cph.userId JOIN usr_booking ub ON u.id=ub.userId WHERE u.id='152'; 

    To order your result by the latest createdOn of all tables, you must first identify the latest createdOn of all tables:

    SELECT userId, max(createdOn) as latestActivity (SELECT userId, max(createdOn) as createdOn FROM cancelPaymentHistory UNION SELECT userId max(createdOn) as createdOn FROM usr_booking UNION  SELECT userId max(createdOn) as createdOn FROM paymentHistory) 

    This result must be joined with the prior query:

    SELECT u.id as userId,ph.bookingId as paymentHistoryBooking,cph.bookingId as CancelBookingId,ub.bookingId as usrBooking  , max(latestActivity) FROM users u JOIN paymentHistory ph ON u.id=ph.userId JOIN cancelPaymentHistory cph ON u.id=cph.userId JOIN usr_booking ub ON u.id=ub.userId JOIN (SELECT userId, max(createdOn) as latestActivity      FROM (SELECT userId, max(createdOn) as createdOn      FROM cancelPaymentHistory      UNION      SELECT userId, max(created_on) as created_on      FROM usr_booking      UNION       SELECT userId, max(createdOn) as createdOn      FROM paymentHistory) a) activity ON activity.userId = u.id WHERE u.id='1' ORDER BY activity.latestActivity DESC; 

    Note, that I still got the ORDER BY in the query. I am assuming you want to run this statement for multiple users, so you can modify the WHERE-Statement like WHERE u.id IN ('1','2','3') and still have a sorted list.

    I have set up a fiddle for you http://sqlfiddle.com/#!9/ea835a/28/0

    • 399 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    It may be a bit offtopic, but anyway. You can program c++ right on iOS devices. Check out CppCode ios app – http://cppcode.info. I believe it helps to learn c and c++ and objective-c later.

    • 0 views
    • 11 answers
    • 0 votes
  • enter image description here

    It’s a category table.

    SELECT  id,         NAME,         parent_category  FROM    (SELECT * FROM category          ORDER BY parent_category, id) products_sorted,         (SELECT @pv := '2') initialisation WHERE   FIND_IN_SET(parent_category, @pv) > 0 AND     @pv := CONCAT(@pv, ',', id) 

    Output:: enter image description here

    • 726 views
    • 15 answers
    • 0 votes
  • Maintain Set of values for each key in a object. Use map and get the updated filtered object. (updated object will be keys which are not have already)

    const all = {};  const updateObject = (obj) =>   Object.fromEntries(     Object.entries(obj).filter(([key, value]) => {       if (!(key in all)) {         all[key] = new Set();       }       const result = !all[key].has(value);       all[key].add(value);       return result;     })   );  const output = arr => arr.map(updateObject);  data = [   {     tier1: "Normal",     tier2: "none",     tier3: "none",     tier4: "none",     tier5: "none",   },   {     tier1: "Urgent",     tier2: "GCC & Labour",     tier3: "new",     tier4: "Cancellation",     tier5: "Cancellation",   },   {     tier1: "Urgent",     tier2: "Foreigner",     tier3: "renew",     tier4: "Cancellation",     tier5: "none",   }, ];    console.log(output(data));

    • 257 views
    • 4 answers
    • 0 votes
  • Asked on July 16, 2020 in Numpy.

    You could use this :

    arr1[:min(arr1.shape[0], arr2.shape[0]), :min(arr1.shape[1], arr2.shape[1])]=arr2[:min(arr1.shape[0], arr2.shape[0]), :min(arr1.shape[1], arr2.shape[1])] 

    without any for loop.

    It’s the same concept you applied in second try, but with a condition to choose minimum length.

    • 339 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    Excellent answers so far but some tidbits are missing. A single leading underscore isn’t exactly just a convention: if you use from foobar import *, and module foobar does not define an __all__ list, the names imported from the module do not include those with a leading underscore. Let’s say it’s mostly a convention, since this case is a pretty obscure corner;-).

    The leading-underscore convention is widely used not just for private names, but also for what C++ would call protected ones — for example, names of methods that are fully intended to be overridden by subclasses (even ones that have to be overridden since in the base class they raise NotImplementedError!-) are often single-leading-underscore names to indicate to code using instances of that class (or subclasses) that said methods are not meant to be called directly.

    For example, to make a thread-safe queue with a different queueing discipline than FIFO, one imports Queue, subclasses Queue.Queue, and overrides such methods as _get and _put; “client code” never calls those (“hook”) methods, but rather the (“organizing”) public methods such as put and get (this is known as the Template Method design pattern — see e.g. here for an interesting presentation based on a video of a talk of mine on the subject, with the addition of synopses of the transcript).

    Edit: The video links in the description of the talks are now broken. You can find the first two videos here and here.

    • 542 views
    • 15 answers
    • 0 votes