gpt4 book ai didi

android - OnClick 未触发两个基本适配器

转载 作者:太空狗 更新时间:2023-10-29 14:28:31 24 4
gpt4 key购买 nike

我正在使用包含一些 TextView 和水平 ListView 的自定义 ListView 。

自定义 ListView 的所有 View 都正确填充并且 OnClick 监听器工作正常。

现在我使用 Second Base Adapter 填充包含图像的水平 ListView 。

填充水平 ListView 后,我尝试单击水平 ListView 中的相对布局,但它没有触发。

这是我的代码:

public class ThreadListNewAdapter extends ArrayAdapter<Thread> {

private Context context;
private ImageLoader imageLoader;
private HorizontialListView horizontialListView;

public ThreadListNewAdapter(Context context, int textViewResourceId,
List<CompressedThread> threadList) {

super(context, textViewResourceId, threadList);
this.context = context;
imageLoader = new ImageLoader(context);

}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

ImageView userImage;
View myView = convertView;

LayoutInflater inflater = (LayoutInflater) context // activity.getLayoutInflater();
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

myView = inflater.inflate(R.layout.popular_new, null);

myView.setTag(threadId);

final View view = myView;

if (mediaList.size() > 0) {
imageLayout.setVisibility(View.VISIBLE);
horizontialListView = (HorizontialListView) myView
.findViewById(R.id.media_horizontal_view);
horizontialListView.setAdapter(new ImageAdapter(mediaList)); //PLACE WHHERE I AM CALLING SECOND ADAPTER
}

view.setTag(position);
view.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
onThreadClick(fThread);
}
});

return myView;
}

class ImageAdapter extends BaseAdapter {

List<Media> mediaList = new ArrayList<Media>();

public ImageAdapter(List<Media> allMediaList) {
mediaList = allMediaList;
}

@Override
public int getCount() {
return mediaList.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int pos = position;
ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.inbox_horizontal_row,
null);
holder.imageView = (ImageView) convertView
.findViewById(R.id.media_image_view);
holder.commentLayout = (RelativeLayout) convertView
.findViewById(R.id.comment_layout);

holder.commentLayout.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Log.v("Clicked", "Clicked" + "" + pos);
}

}); // CLICK EVENT IS NOT FIRING HERE

convertView.setTag(holder);

} else {
holder = (ViewHolder) convertView.getTag();
}
holder.mediaId = position;
return convertView;
}
}

class ViewHolder {
ImageView imageView;
TextView commentText, likeText;
RelativeLayout commentLayout;
int mediaId;
}

水平 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/media_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<RelativeLayout
android:id="@+id/like_comment_layout"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:background="#80000000"
android:clickable="true"
android:focusable="true" >

<RelativeLayout
android:id="@+id/comment_layout"
android:layout_width="60dp"
android:layout_height="30dp"
android:orientation="horizontal" >

<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_marginLeft="5dp"
android:src="@drawable/comment" />
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
</LinearLayout>

最佳答案

将您的相对布局的可点击和可聚焦属性设置为 true,并将其所有子项设置为 false。

关于android - OnClick 未触发两个基本适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9356732/

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