为什么只有listview的最后一行改变它的背景颜色,无论在android中点击哪一行?

时间:2014-05-14 08:58:25

标签: android listview simpleadapter

我使用Listview生成了SimpleAdapter,我使用了fortysevendegree swiplelistview库。此处swipy是我的listview id。问题是,我点击最后一行的任何一行只会将其背景更改为黑色。我想仅更改所选行的背景颜色。我的代码如下。由于我是新手,请一步一步解释我该怎么做。

mycontacts.java

  SimpleAdapter k=new SimpleAdapter(getActivity(),val,R.layout.contact2,new String[]{"name","path","id"},new int[]{R.id.example_itemname,R.id.path,R.id.contactid})
    {

        @Override
            public View getView (int position, View convertView, ViewGroup parent)
            { 
     final View v = super.getView(position, convertView, parent);
     final RelativeLayout l=(RelativeLayout)v.findViewById(R.id.front);
     final View vh=(View)v.findViewById(R.id.view1);
     final View vv=(View)v.findViewById(R.id.viewvert);
     final View orange=(View)v.findViewById(R.id.vieworange);
     ImageView purple=(ImageView)v.findViewById(R.id.imageView1);
     swipy.setSwipeListViewListener(new BaseSwipeListViewListener(){

@Override
public void onClickFrontView(int position) {
    // TODO Auto-generated method stub  
    super.onClickFrontView(position);
          l.setBackgroundColor(Color.BLACK);
vh.setVisibility(v.INVISIBLE);
vv.setVisibility(v.INVISIBLE);
    orange.setVisibility(v.VISIBLE);
    name.setTextColor(Color.WHITE);
Toast.makeText(getActivity(),"swipe"+position,Toast.LENGTH_LONG).show();
    }
}
     return v;
            }
    };
        swipy.setAdapter(k);

0 个答案:

没有答案