仿酷狗音乐列表点击item子控件展开功能

也是项目需要大家先来看看效果图

仿酷狗音乐列表点击item子控件展开功能_第1张图片

就是这样不过我的项目可能下面没有这么多项而已,说一下思路:

实际上下面展开的哪一块是被隐藏起来了的,可以获取itme的事件点击,接收点击事件展开(显示出来),点击另外的隐藏起来

下面是我的效果图(大家可以自己设置样式,我的比较丑)

仿酷狗音乐列表点击item子控件展开功能_第2张图片

好图片有点大,但是看的爽对不!下面贴代码


public class MainActivity extends Activity  {
	private ListView mListView;
	private ListAdapter mAdapter;

	@Override
	public 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.changeImageVisable(position);
	// }

	MyClickListener listener = new MyClickListener() {
		@Override
		public void myOnClick(int position, View v) {
			Toast.makeText(MainActivity.this, "修改", 2000).show();
		}
	};

	MyClickListener2 listener2 = new MyClickListener2() {
		public void myOnClick2(int position, View v) {

			Toast.makeText(MainActivity.this, "重置", 2000).show();
		}
	};

	MyClickListener3 listener3 = new MyClickListener3() {

		@Override
		public void myOnClick3(int position, View v) {
			mAdapter.changeImageVisable(position);
		}
	};
}

Activity的xml代码:



    

适配器代码:

public class ListAdapter extends BaseAdapter {
	private Context mContext;
	private int mLastPosition = -1;
	private MyClickListener 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;
	}

	@Override
	public int getCount() {
		return 100;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = new Holder();
		if (convertView == 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 {
		@Override
		public 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((Integer) v.getTag(), v);
		}

		public abstract void myOnClick2(int position, View v);
	}

	public static abstract class MyClickListener3 implements OnClickListener {
		public void onClick(View v) {
			myOnClick3((Integer) 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 {
			mLastPosition = -1;
		}
		notifyDataSetChanged();
	}
}

listview的item的list_item.xml代码:




    

        

        

            

            

                

                
            
        

        
    

    

        

        
    


嗯!到这里就差不多了 我会把 代码上传上去有兴趣的同志可以看看





你可能感兴趣的:(Android,一些功能)