listView中的涟漪效应

时间:2016-01-11 11:50:59

标签: android listview ripple

我有一个工作正常的列表视图,涟漪效果适用于列表项目按下。但我添加并使用slide expandable list view 库来增加listvview的功能。一切正常但在添加库后,项目点击上的涟漪不起作用

我的列表适配器的getview()

public View getView(final int position, View view, ViewGroup parent)
{
    final ViewHolder holder;
    if(view == null){
        holder = new ViewHolder();
        view = inflater.inflate(R.layout.testlistitem,null);
        holder.listHeading = (TextView) view.findViewById(R.id.beg_list_itemTextView);

        holder.listHash = (TextView) view.findViewById(R.id.listview_hashtags);
        holder.alphabetList = (ImageView) view.findViewById(R.id.beg_list_itemImageView);

        holder.favariteImage = (ImageView) view.findViewById(R.id.favbtn);

        view.setTag(holder);

    }else{
        holder = (ViewHolder) view.getTag();
    }
    CodeList codes = (CodeList) getItem(position);
    holder.listHeading.setText(codeList.get(position).getListHeading());
    holder.listHash.setText(codeList.get(position).getListHashText());
    imageLoader.DisplayImage(codeList.get(position).getAlphabetimg(),
                             holder.alphabetList);


    if (checkFavoriteItem(codes)) {
        holder.favariteImage.setImageResource(R.drawable.favorite);
        holder.favariteImage.setTag("yes");
    } else {
        holder.favariteImage.setImageResource(R.drawable.unfavorite);
        holder.favariteImage.setTag("no");
    }                    


    view.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0){
                Intent intent = new Intent(context, SingleItemView.class);

                //intent.putExtra("listheading",
                //       (codeList.get(position).getListHeading()));
                //intent.putExtra("alphabetimg",
                //              (codeList.get(position).getAlphabetimg()));

                intent.putExtra("demovideo",
                                (codeList.get(position).getDailogdemovideo()));


                context.startActivity(intent);

            }
        });     


    return view;
}

主要活动oncrate()

listview = (ListView) findViewById(R.id.inter_layoutListView);
        // Pass the results into ListViewAdapter.java
        adapter = new FinalAdapter(InterActivity.this,
                                      codelist);

        listview.setAdapter(new SlideExpandableListAdapter(adapter, R.id.expandbutton, R.id.expandable));

1 个答案:

答案 0 :(得分:0)

public class ASummary extends Activity implements OnClickListener{

//.....
@Override
    protected void onCreate(Bundle savedInstanceState) {

        ///...
adapter = new FinalAdapter(InterActivity.this,
                                      codelist,this);
///...
}
//....
@Override
    public void onClick(View v) {
        int id = (Integer) v.getTag();

      }

}

FinalAdapter类中创建构造函数和OnClickListener变量:

private OnClickListener listener;
FinalAdapter(Context ctx,codelist, OnClickListener listener ){

///super....

this.listener = listener;
}

然后在getView: 使用

view.setTag(position);
view.setOnClickListener(listener);