listview,headerview,listview上的布局 跟随listview一起滑动

我想做一个这样的的布局图片说明
下面是listview,我就是不清楚上面怎么做,如果用headerView 怎么才能实现响应的的点击响应事件!

public class MainActivity extends Activity {
private ListView lv;
private List list;
private MyAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initData();
    adapter = new MyAdapter(MainActivity.this, list);
    final View inflate = LayoutInflater.from(getApplicationContext())
            .inflate(R.layout.header, null);

    lv.addHeaderView(inflate, null, false);

    inflate.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d("---->", v.getId() + "");
            switch (v.getId()) {
            case R.id.img1:
                Toast.makeText(MainActivity.this, "imag1", 0).show();
                break;
            case R.id.img2:
                Toast.makeText(MainActivity.this, "imag2", 0).show();
                break;
            }
        }
    });

    lv.setAdapter(adapter);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
             if(arg2==0){
             inflate.setOnClickListener(new View.OnClickListener() {

             @Override
             public void onClick(View v) {
             // TODO Auto-generated method stub
             Log.d("---->", v.getId()+"");
             switch (v.getId()) {
             case R.id.img1:
             Toast.makeText(MainActivity.this, "imag1", 0).show();
             break;
             case R.id.img2:
             Toast.makeText(MainActivity.this, "imag2", 0).show();
             break;
             }
             }
             });
             }
            Toast.makeText(MainActivity.this, list.get(arg2), 0).show();
        }

    });
}

private void initData() {
    // TODO Auto-generated method stub
    lv = (ListView) findViewById(R.id.lv_listview);
    list = new ArrayList<String>();
    for (int i = 0; i < 20; i++) {
        list.add("this is item" + i);
    }
}

求大神帮忙,最好来代码,!我就是不知道listview上的布局要怎么做(listview上的布局会跟随listview一起滑动的~~!)
查看全部
qq_26687333
qq_26687333
2015/08/04 07:55
  • 布局
  • 点赞
  • 收藏
  • 回答
    私信

3个回复