Recent

Author Topic: [LAMW]- change the background JsRecyclerView item  (Read 1806 times)

juank1971

  • Full Member
  • ***
  • Posts: 112
[LAMW]- change the background JsRecyclerView item
« on: November 27, 2020, 03:52:26 pm »
Hi. I need to change the background color of an item in a
JsRecyclerView

I try setItemBackgroundColor but I couldn't, it didn't work

juank1971

  • Full Member
  • ***
  • Posts: 112
Re: [LAMW]- change the background JsRecyclerView item
« Reply #1 on: November 28, 2020, 02:34:48 am »
Or other option is try to configure one example to the jsRecyclerView with the cfPanel itemcontent

Because the AppCompactRecyclerViewDemo1 no show how use this content
cfPanel

Y try bat i have some errors.
I try use cfPanel to bacground the item and change color. To this widget.

Any idea

juank1971

  • Full Member
  • ***
  • Posts: 112
Re: [LAMW]- change the background JsRecyclerView item
« Reply #2 on: November 28, 2020, 03:14:39 am »
I try to see the code in the jsRecyclerView.java

In the setItemBackgroundColor procedure
Bat I do not understand the the way to pass the color parameters and I don't understand what the parametr int round means.

Is this:
   public void SetItemBackgroundColor( int position, int color, int round ){
       int countpanel = itemList.get(position).countpanel;
       
       if( countpanel > 0 )
          itemList.get(position).panel[0] = Integer.toString(color)+"@"+Integer.toString(round);                 
    }

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: [LAMW]- change the background JsRecyclerView item
« Reply #3 on: December 01, 2020, 01:47:19 am »

Hi,  @ADiV !!

Can you help here?

What about a simple demo?
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

ADiV

  • Jr. Member
  • **
  • Posts: 90
    • ADiV Software
Re: [LAMW]- change the background JsRecyclerView item
« Reply #4 on: December 01, 2020, 06:22:53 pm »

Hi,  @ADiV !!

Can you help here?

What about a simple demo?

First you must create a "Panel" object that encompasses all the objects of the "ReciclerView". This is the one that will change the background color, see this code:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  2. begin
  3.   //jsRecyclerView1.SetClipToPadding(False);
  4.   jsRecyclerView1.SetItemContentLayout(jPanel1.View,  True {cardview});   //custom item view!
  5.  
  6.   //jsRecyclerView1.SetItemContentDelimiter('|');    //default
  7.  
  8.   //the sequence maps the order of the content added on  "jsRecyclerView1.Add(....)"
  9.   //jsRecyclerView1.SetItemContentFormat('IMAGE|TEXT|TEXT|CHECK|RATING|SWITCH');
  10.  
  11.   //or
  12.   jsRecyclerView1.ClearItemContentFormat; // Need for reinit activity
  13.   jsRecyclerView1.AddItemContentFormat(cfPanel);
  14.   jsRecyclerView1.AddItemContentFormat(cfImage);
  15.   jsRecyclerView1.AddItemContentFormat(cfText);   // one text
  16.   jsRecyclerView1.AddItemContentFormat(cfText);   // another text
  17.   jsRecyclerView1.AddItemContentFormat(cfCheck);
  18.   jsRecyclerView1.AddItemContentFormat(cfRating);
  19.   jsRecyclerView1.AddItemContentFormat(cfSwitch);
  20.   jsRecyclerView1.SetItemContentFormat();
  21.  
  22.   jsRecyclerView1.Add( intToStr(GetARGBJava(Fcustomcolor, colbrWhite)) + '@20|don_quixote@drawable|Do you see friend Sancho...|thirty or forty hulking giants?|OK@0|2.5|ON:OFF@0');
  23.   jsRecyclerView1.Add( intToStr(GetARGBJava(Fcustomcolor, colbrWhite)) + '@20|lance.png@assets|Take care...|there are not giants but windmills...|OK@0|3.5|Sound@0');
  24.  
  25.   (*Notes:
  26.  
  27.   .Image source [possibility] example:
  28.  
  29.         lance.png@assets            <---- project folder  "assets"
  30.         ic_launcher@drawable      <---- project folder  "res/drawable" dont use the file extension!!!
  31.         url@http://icons.iconarchive.com/icons/alecive/flatwoken/128/Apps-Google-Chrome-App-List-icon.png    <-- get from url/location
  32.         picture21.png@download         <----- device folder download [need run time permission!]
  33.         image007.png@sdcard            <----- device sdcard [need run time permission!]
  34.  
  35.    .Check: OK@1 --> set caption=OK  and:  1=checked, 0=unchecked      --initial state
  36.    .Rating: 2.5 --> stars settings     --initial state
  37.    .Switch: OFF:ON@0 --> set slide text ("OFF" or "ON" by state) and:  0=unchecked/Off  --initial state
  38.    .Switch: Sound@1 --> set caption=Sound  and: 1=checked/On    --initial state
  39.   *)
  40.  
  41. end;

And to change the color just do this:

Code: Pascal  [Select][+][-]
  1.   jsRecyclerView1.SetItemBackgroundColor(itemPosition, colbrRed, 20);
  2.   jsRecyclerView1.Refresh(itemPosition);
  3.  

I use the same thing in my app "Listacom": https://play.google.com/store/apps/details?id=tr3e.MarkListFree to select a list if you long click on an item.

juank1971

  • Full Member
  • ***
  • Posts: 112
Re: [LAMW]- change the background JsRecyclerView item
« Reply #5 on: December 01, 2020, 09:15:19 pm »
ok thank you very much I will try it,

juank1971

  • Full Member
  • ***
  • Posts: 112
Re: [LAMW]- change the background JsRecyclerView item
« Reply #6 on: December 02, 2020, 03:08:27 am »
beautiful, the result  , works perfect. thanks .

 

TinyPortal © 2005-2018