首页 > 代码库 > android的ListView点击item使item展开的做法

android的ListView点击item使item展开的做法

直接上代码把,主要是重新给item measure高度,直接上代码把

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends Activity {

	private ArrayList<MyData> myList = new ArrayList<MyData>();
	private myAdapter myAdapter;
	private LayoutInflater inflater = null;
	private int oldPostion = -1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final ListView list = (ListView) findViewById(R.id.draggable_list);
		MyData data = http://www.mamicode.com/new MyData();>
Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="50dp" >

    <TextView
        android:id="@+id/item1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="Header"
        android:textColor="#000000"
        android:textSize="20sp" >
    </TextView>

    <RelativeLayout
        android:id="@+id/item2"
        android:layout_below="@id/item1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="35dp"
        android:background="#fffeee"
        android:visibility="gone" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:text="Expand"
            android:textColor="#000000"
            android:textSize="16sp" >
        </TextView>
    </RelativeLayout>


</RelativeLayout>

效果图:


代码:http://download.csdn.net/detail/baidu_nod/7765251