Rich-text Reply

I can't edit the lists written by ListView for Android.

kuesy 01-27-16
Accepted Solution

I can't edit the lists written by ListView for Android.

 I use Optimizely.setOptimizelyId method in getView.

Is it possible to edit for using getView?

Level 2

Pam 01-29-16
 

Re: I can't edit the lists written by ListView for Android.

Hi @kuesy,

 

Thanks for reaching out! You should be able to add an OptimizelyId in getView. Do you have the code you have written for what's not working for you? I was able to get this up on my side with the example code below.  setOptimizelyId is called near the end of the method.

 

Let me know if this works for you!  Happy to help investigate this further if this does not work for you.

 

Cheers,

Pam

 

public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;

if (convertView == null) {
gridView = new View(context);

// get layout from mobile.xml
gridView = inflater.inflate(R.layout.activity_live_variables_item, null);


// set image based on selected text
ImageView imageView = (ImageView) gridView

.findViewById(R.id.product_image_view);

TextView nameView = (TextView) gridView.findViewById(R.id.text_view_name);
nameView.setText(itemNameArray[position]);

TextView msrpView = (TextView) gridView.findViewById(R.id.test_view_msrp);
msrpView.setText(msrpArray[position]);
double discount = 0.25;

TextView saleView = (TextView) gridView.findViewById(R.id.text_view_sales_price);

// [OPTIMIZELY] Examples of how to use live variable values (Part 2 of 2)
saleView.setText(Float.toString(round((1.0f - discountVariable.get()) * Float.parseFloat(msrpArray[position]), 2)));

imageView.setImageResource(mThumbIds[position]);
} else {
gridView = (View) convertView;
}
// [OPTIMIZELY] Example of when to set the Optimizely ID
Optimizely.setOptimizelyId("itemdude" + position, gridView);
return gridView;
}

 

 

Pam
Optimizely
kuesy 02-03-16
 

Re: I can't edit the lists written by ListView for Android.

[ Edited ]

Hi @Pam

 

Thank you for giving me good advice!

 

I could edit the text and image in getView.

But it still remains in doubt.

When I scrolled from the edited text(or image) and returned to the edited text, the edited text was initialized.

It is difficult to explain, so I show in the image.

I would appreciate your teaching.

 

1. Edited text is displayed.

edit1.jpg

 

2.Scroll down the screen.

edit2.jpg

 

3.Scroll up the screen. "EDITED" is initialized.

edit3.jpg

 

 

My writing code is as follows.

public View getView(int position, View convertView, ViewGroup parent) {
            //item array set
            CustomData item = (CustomData) getItem(position);

            LayoutInflater inflater =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View gridView;
            
            if (null == convertView) {
                gridView=new View(context);
                gridView=inflater.inflate(R.layout.custom_layout, null);
            }else{
                gridView = (View) convertView;
            }

            //set image and text
            ImageView imageView;
            imageView = (ImageView) gridView.findViewById(R.id.image);
            imageView.setImageBitmap(item.getImageData());
            imageView.setBackgroundResource(R.drawable.border);
            TextView textView;
            textView = (TextView) gridView.findViewById(R.id.text);
            textView.setText(item.getTextData());

            // OPTIMIZELY CUSTOMID SET
            Optimizely.setOptimizelyId("itemdude"+position,gridView);

            return gridView;
        }

 

Regards,

Kuesy

 

Level 2
Pam 02-04-16
 

Re: I can't edit the lists written by ListView for Android.

Hi @kuesy

 

That is indeed interesting behavior!  One thing to consider is to possibly set the optimizelyId as the text (and modify the textView based on the text), rather than based on the position it is in the list.

 

To verify that this is working as expected, you can use Preview:

https://help.optimizely.com/hc/en-us/articles/215238728-Preview-Mode-iOS-Android-

 

Do you want to try that?  That will likely better match the behavior you are looking for.  Feel free to reach out if you have additional questions on this!

 

Cheers,

Pam

Pam
Optimizely
kuesy 02-04-16
 

Re: I can't edit the lists written by ListView for Android.

Hi @Pam

 

I appreciate your prompt response.


Well, I tried many things to try using  the preview, but it was still not good.

I think, text in the list is setted as item of the position whenever the getView is called.

 

I would like to try to check in a different code.

 

Thank you for your advice!

 

 

Kind regards,

Kuesy

Level 2