gpt4 book ai didi

android - listView 中的波纹效果

转载 作者:太空狗 更新时间:2023-10-29 14:51:37 27 4
gpt4 key购买 nike

我有一个工作正常的 ListView ,波纹效果适用于列表项按下。但我已经添加并使用了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;
}

ma​​inactivity 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));

最佳答案

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);

关于android - listView 中的波纹效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34720873/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com