首页 > 代码库 > 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();"11"; myList.add(data); data = http://www.mamicode.com/new MyData();"22"; myList.add(data); data = http://www.mamicode.com/new MyData();"33"; myList.add(data); data = http://www.mamicode.com/new MyData();"44"; myList.add(data); data = http://www.mamicode.com/new MyData();"55"; myList.add(data); data = http://www.mamicode.com/new MyData();"66"; myList.add(data); data = http://www.mamicode.com/new MyData();"77"; myList.add(data); inflater = LayoutInflater.from(this); TextView header = (TextView)inflater.inflate(R.layout.header, null); TextView footer = (TextView)inflater.inflate(R.layout.footer, null); //list.addFooterView(footer); //list.addHeaderView(header); myAdapter = new myAdapter(); list.setAdapter(myAdapter); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MyData data = http://www.mamicode.com/myList.get(position);>
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
android的ListView点击item使item展开的做法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。