Parody Dog music list click the Item child controls expand feature

Source: Internet
Author: User

It's also a project that we need to see.


That's it. But my project may not have so many items below, say the idea:

In fact, which piece of the following expansion is hidden, you can get Itme event Click, receive click events expand (Show), click on another hidden

Here is my (everyone can set their own style, I am more ugly)


Good picture is a bit big, but look cool right no! Paste the following code


public class Mainactivity extends Activity {private ListView mlistview;private listadapter madapter; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Mlistview = (ListView) Findviewbyid (r.id.list); madapter = new ListAdapter (this, listener, Listener2, Listener3); Mlistview.setadapter (Madapter);//mlistview.setonitemclicklistener (this);} @Override//public void Onitemclick (adapterview<?> parent, view view, int position,//long ID) {//Madapter.chang Eimagevisable (position);//}myclicklistener listener = new Myclicklistener () {@Overridepublic void Myonclick (int Position, View v) {toast.maketext (mainactivity.this, "Modify", "N"). Show ();}}; MyClickListener2 listener2 = new MyClickListener2 () {public void MyOnClick2 (int position, View v) {Toast.maketext (mainact Ivity.this, "Reset", "$"). Show ();}}; MyClickListener3 Listener3 = new MyClickListener3 () {@Overridepublic void myOnClick3 (int position, View v) {Madapter.Changeimagevisable (position);}};} 

XML code for activity:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android:orientation= "vertical"    tools:context= ". Mainactivity ">    <listview        android:id=" @+id/list "        android:layout_width=" Match_parent        " android:layout_height= "Wrap_content"/></linearlayout>

Adapter Code:

public class ListAdapter extends Baseadapter {private Context mcontext;private int mlastposition = -1;private Myclickliste NER mlistener;private MyClickListener2 mlistener2;private MyClickListener3 mlistener3;public listadapter (Context Context, Myclicklistener Mlistener,myclicklistener2 mListener2, MyClickListener3 mListener3) {this.mcontext = context; This.mlistener = Mlistener;this.mlistener2 = Mlistener2;this.mlistener3 = MListener3;} @Overridepublic int GetCount () {return 100;} @Overridepublic Object getItem (int position) {return null;} @Overridepublic long Getitemid (int position) {return 0;} @Overridepublic view GetView (int position, view Convertview, ViewGroup parent) {Holder Holder = new Holder (); if (CONVERTVI EW = = null) {Layoutinflater inflater = Layoutinflater.from (mcontext); Convertview = Inflater.inflate (R.layout.list_item , null); Holder.textview = (TextView) Convertview.findviewbyid (R.id.textview); holder. Uefaview = (ImageView) Convertview.findviewbyid (R.ID.IMAGE_UEFA); Holder.mascotView = (ImageView) Convertview.findviewbyid (r.id.image_mascot); holder.hint = Convertview.findviewbyid (R.id.hint_ image); Convertview.settag (holder);} else {holder = (holder) Convertview.gettag ();} Holder.textView.setText ("Hello,it is" + position); if (position = = mlastposition) {holder.hint.setVisibility ( view.visible);} else {holder.hint.setVisibility (view.gone);} Holder. Uefaview.setonclicklistener (Mlistener); holder. Uefaview.settag (position);//holder.mascotview.setonclicklistener (MListener2); Holder.mascotView.setTag (position ); Holder.textView.setOnClickListener (MListener3); Holder.textView.setTag (position); return Convertview;} public static abstract class Myclicklistener implements Onclicklistener {@Overridepublic void OnClick (View v) {Myonclick ( (Integer) V.gettag (), v);} public abstract void Myonclick (int position, View v);} public static abstract class MyClickListener2 implements Onclicklistener {public void OnClick (View v) {MyOnClick2 (intege R) V.gettag (), v);} public abstract void MyOnClick2(int position, View v);} public static abstract class MyClickListener3 implements Onclicklistener {public void OnClick (View v) {MyOnClick3 (intege R) V.gettag (), v);} public abstract void MyOnClick3 (int position, View v);} Class Holder {TextView textview;imageview uefaview;imageview mascotview; View hint;} public void changeimagevisable (int position) {if (position! = mlastposition) {mlastposition = position;} else {Mlastpositi on =-1;} Notifydatasetchanged ();}}

The List_item.xml code of the ListView item:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" wrap_content "android:orientation=" vertical " > <relativelayout android:layout_width= "match_parent" android:layout_height= "60DP" > < ImageView android:id= "@+id/iv_status" android:layout_width= "Wrap_content" Android:layout_        height= "Wrap_content" android:layout_marginright= "20DP" android:src= "@drawable/normal"/> <linearlayout android:id= "@+id/ll_context" android:layout_width= "200DP" android:layout            _height= "60DP" android:layout_torightof= "@id/iv_status" android:orientation= "vertical" >                <textview android:id= "@+id/tv_context" android:layout_width= "Wrap_content" Android:layout_height= "Wrap_conTent "android:text=" asdf "/> <linearlayout android:layout_width=" 150DP "                    android:layout_height= "60DP" android:orientation= "Horizontal" > <textview Android:id= "@+id/tv_select" android:layout_width= "Wrap_content" a                    ndroid:layout_height= "Wrap_content" android:text= "asdf"/> <textview Android:id= "@+id/tv_setlen" android:layout_width= "Wrap_content" android:layout _height= "Wrap_content" android:text= "asdf"/> </LinearLayout> </linearlay            out> <textview android:id= "@+id/textview" android:layout_width= "Wrap_content"            android:layout_height= "60DP" android:layout_alignparentright= "true" android:gravity= "center" android:text= "Expand"           Android:textsize= "20sp"/> </RelativeLayout> <linearlayout android:id= "@+id/hint_image        "Android:layout_width=" match_parent "android:layout_height=" 60DP "android:orientation=" Horizontal " Android:visibility= "Gone" > <imageview android:id= "@+id/image_uefa" android:layou T_width= "0DP" android:layout_height= "60DP" android:layout_weight= "1" android:src= "@drawab            Le/uefa "/> <imageview android:id=" @+id/image_mascot "android:layout_width=" 0DP "    android:layout_height= "60DP" android:layout_weight= "1" android:src= "@drawable/mascot"/> </LinearLayout></LinearLayout>

Well! It's almost over here, and I'm going toCodeThe comrades who are interested in uploading can see





Parody Dog music list click the Item child controls expand feature

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.