Thank you..finally found some way to go, perhaps not best one, but
working :)

On Oct 1, 3:09 am, Streets Of Boston <[email protected]> wrote:
> I think you can't use the '[ ]' operator on the JSONArray.... (if
> valArray2 is a JSONArray).
> [ ] only works in regular arrays.
>
> Look at the JSONArray class and see what method is implemented in that
> class to return an JSON element at position 'x'.
>
> And you have to make sure that the value provided to the 'setText'
> method is a CharSequence (e.g. a String).
>
> If you're not familiar with Java, i strongly suggest you do become
> familiar with it :-).
>
> On Sep 30, 3:50 pm, vorcigernix <[email protected]> wrote:
>
> > Thanks. This moved my understanding of whole BaseAdapter (which is not
> > data adapter at all). Now I am frozen on some casting unknown to me
> > (probably). I created code:
>
> >         public View getView(int position, View convertView, ViewGroup
> > parent) {
> >             // A ViewHolder keeps references to children views to
> > avoid unneccessary calls
> >             // to findViewById() on each row.
> >             ViewHolder holder;
>
> >             // When convertView is not null, we can reuse it directly,
> > there is no need
> >             // to reinflate it. We only inflate a new View when the
> > convertView supplied
> >             // by ListView is null.
> >             if (convertView == null) {
> >                 convertView = mInflater.inflate
> > (R.layout.list_item_icon_text, null);
>
> >                 // Creates a ViewHolder and store references to the
> > two children views
> >                 // we want to bind data to.
> >                 holder = new ViewHolder();
> >                 holder.text = (TextView) convertView.findViewById
> > (R.id.text);
> >                 holder.text2 = (TextView) convertView.findViewById
> > (R.id.text2);
> >                 holder.icon = (ImageView) convertView.findViewById
> > (R.id.icon);
>
> >                 convertView.setTag(holder);
> >             } else {
> >                 // Get the ViewHolder back to get fast access to the
> > TextView
> >                 // and the ImageView.
> >                 holder = (ViewHolder) convertView.getTag();
> >             }
>
> >             // Bind the data efficiently with the holder.
>
> >             holder.text.setText(valArray2[position]);
> >             holder.text2.setText(valArray2[position]);
> >             holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 :
> > mIcon2);
> >             .......
>
> > Which is basically list14 example from SDK. But, holder.text.setText
> > (valArray2[position]); returns error that Array is expected and mine
> > is JSONArray. How to cast my JSONArray to expected format?
>
> > On Sep 30, 6:37 pm, Streets Of Boston <[email protected]> wrote:
>
> > > Implement your subclass of BaseAdapter (e.g. JSONArrayAdapter).
> > > Implement/override the getCount(), getItem(int position), etc. to make
> > > your BaseAdapter a proper list-adapter around your jsonarray.
>
> > > Implement the getView method; it provides the 'position' and
> > > 'contentView' parameters.
> > > - Use position and getItem(position) to obtain anjson-element from
> > > your jsonarray.
> > > - re-use contentView or create a brand-new one if it is null:
> > >   - Assign text/images to the contentView (or its child-view) based
> > > on
> > >     thejson-element you got.
>
> > > Then assign an instance of your JSONArrayAdapter to your list- or grid-
> > > view.
> > > And viola. It should work :)
>
> > > Take a look at the 'API Demo' in the Android SDK for examples.
>
> > > On Sep 29, 3:45 pm, vorcigernix <[email protected]> wrote:
>
> > > > Ok, I don't get a BaseAdapter logic, I assume because I am not used to
> > > > java. I found tons of examples on net (mostly for drawing pictures
> > > > etc) but it make no sense to me. For example, list4 from sdk do
> > > > something similar, but...where are they binding data? I see where data
> > > > is set to custom class, but what actually returns data from
> > > > BaseAdapter? GetView?
> > > > Thanks for any clarification
> > > > Adam
>
> > > > On Sep 28, 8:15 pm, Mark Muphy <[email protected]> wrote:
>
> > > > > vorcigernix wrote:
> > > > > > Hello,
> > > > > > I made my application from various examples and sources, so now I 
> > > > > > have
> > > > > > filled jsonarray and preparedlistview(with custom rows formatting).
> > > > > > Now I need to replace
>
> > > > > > ListAdapter myAdapter =(new ArrayAdapter<String>
> > > > > > (this,R.layout.rowlayout, R.id.TextView01, values));
>
> > > > > > with myjsonarray based adapter. All I found is some technique to
> > > > > > iterate through alljsonrecords and construct string array. It sound
> > > > > > like perverse to me, is it really necessary?
>
> > > > > Create your own adapter class from BaseAdapter, and you can traverse
> > > > > yourJSONhowever you want.
>
> > > > > --
> > > > > Mark Murphy (a Commons 
> > > > > Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> > > > > Need Android talent? Ask on 
> > > > > HADO!http://wiki.andmob.org/hado-Hidequotedtext -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to