Some processing of the ListView nesting GridView (click on the GridView entry to be able to display his position in the ListView) (optimized handling of this article, not every time new Onitemclicklistener)

Source: Internet
Author: User

A few days ago wrote the Click on the GridView entry, can show his position in the ListView, then the processing is in the ListView adapter in the GetView method every time the new GridView Onitemclicklistener, This is obviously unreasonable,

/** GridView Entry Click to listen */    Private Gvonitemclicklistener mgvonitemclicklistener;//Members

This is the entrance to the fragment:

@Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {View View= Inflater.inflate (R.layout.fragment_message_firends,NULL);//ViewGroup?Butterknife.bind ( This, view); Mobserver=NewMyobserver ();//create an Observer object//create a control that accesses the networkMessage_net_control Control =NewMessage_net_control ( This); Control.getfriendssharefromserver ();//accessing the network and parsing the JSONMlistview.setdivider (NULL); Mgvonitemclicklistener =new Gvonitemclicklistener ();    returnview; }

This is the GetView method for the ListView adapter:

@Override PublicView GetView (intI, View Convertview, ViewGroup viewgroup) {            FinalViewholder Holder; if(Convertview! =NULL) {Holder=(Viewholder) Convertview.gettag (); } Else{Convertview= View.inflate (Uiutils.getcontext (), R.layout.lv_item_message_friends,NULL); Holder=NewViewholder (Convertview);            Convertview.settag (holder); }            //get a share of the newsMessage_responce_info.everyshareinfo Info =Mresults_list.get (i); //get a collection of all replies that are currently sharing dynamicarraylist<message_responce_info.everyshareinfo.reply> Replys =info.getpub_com (); //Remove comments before dynamically adding comments all sub-view in linear layoutholder.ll_comment_message_friends.removeAllViews ();  for(intj = 0; J < Replys.size (); J + +) {TextView TextView=NewTextView (Uiutils.getcontext ()); Textview.setpadding (0, 8, 0, 0); Textview.settext (Replys.get (j). Getpc_name ()+ ": " +Replys.get (j). Getpc_txt ());                Textview.settextcolor (Color.dkgray);            Holder.ll_comment_message_friends.addView (TextView); } holder.tvUserName.setText (Info.getpub_frd_name ());//set the name of a friend's dynamic shareHolder.tvTime.setText (Info.getpub_datetime ());//set the time to share this dynamicHolder.tvSaySth.setText (Info.getpub_context ());//set up content that is shared dynamicallyArrayList<String> small_pics = info.getpub_th_img ();//talk about the thumbnail collection of pictures Holder.gv.setTag (i); // sets a location marker for the current GridView //when setting Gridviewadapter, first pass in the ListView entry locationMessage_friends_gridviewadapter Gridadapter =NewMessage_friends_gridviewadapter (small_pics); Holder.gv.setAdapter (gridadapter);//set the adapter for the GridView//Set entry for GridView Click to listenHolder.gv.setOnItemClickListener (Mgvonitemclicklistener); //Show user PictureImageloader.getinstance (). DisplayImage (Globalconstant.server_url + "/" +Info.getpub_frd_head (), holder.ivuserface); returnConvertview; }

Tap Listen, in the member

 /**Custom GridView Click-to-Listen*/    classGvonitemclicklistenerImplementsadapterview.onitemclicklistener{/**         *         * @paramAdapterview equivalent to Holder,listview's entry, here equivalent to the Gridviewex in the listview *@paramView represents the GridView entry *@paramPosition the entry location in the GridView *@paramL*/@Override Public voidOnitemclick (adapterview<?> adapterview, view view,intPositionLongl) { int lv_item_position= (Integer) Adapterview.gettag (); // the location of the GridView in the ListView entry //Click on this message to sayMessage_responce_info.everyshareinfo Shareinfo =Mresults_list.get (lv_item_position); ArrayList<String> big_pics = shareinfo.getpub_img ();//Large Map CollectionIntent Intent =NewIntent (Uiutils.getcontext (), messageimageshowactivity.class); Intent.putstringarraylistextra ("Bigpics", big_pics);//send a big picture of the pictures together .Intent.putextra ("bigpicpostion", position);//tell the picture where you clicked.startactivity (Intent); }    }

This time only new one onitemclicklistener, and also achieved the effect.

Some processing of the ListView nesting GridView (click on the GridView entry to be able to display his position in the ListView) (optimized handling of this article, not every time new Onitemclicklistener)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.