gpt4 book ai didi

java - 将 Spinner 包含在 ListView 中后无法单击 ListView

转载 作者:太空宇宙 更新时间:2023-11-04 14:46:39 25 4
gpt4 key购买 nike

我在行 XML 文件中的自定义适配器类上使用了以下 XML,并且还添加了我的自定义适配器类。当我点击 Spinner 后,无法点击项目点击上的 ListView 。如何解决这个问题呢?

我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/exam_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >

<TextView
android:id="@+id/qeuestion_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="qwq"
android:textColor="@color/Black"
android:textSize="18sp" />

<ImageView
android:id="@+id/img_select_question"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="@drawable/select_question" />

<Spinner
android:id="@+id/marks_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/img_select_question"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="10dp"
android:prompt="@string/tv_chapter" />

</RelativeLayout>

将值设置为自定义类的微调器。所以我不知道它是否更好。也同样有助于解决单击 ListView 问题。

我的适配器Java代码:

 public class Question_list_adapter  extends BaseAdapter{

private LayoutInflater l_Inflater;
Activity obj_a;
List<Questions_Details> question_list;
private static class ViewHolder {
public DataHolder data;
public TextView qeuestion_name;
public ImageView img_select_question;
public Spinner marks_spinner;
}

public Question_list_adapter(Activity activity,List<Questions_Details> list_question_Details) {
this.obj_a=activity;
this.question_list =list_question_Details;
l_Inflater = LayoutInflater.from(activity);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return question_list.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return question_list.get(position);
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View vi = convertView;

if(vi==null)
vi = l_Inflater.inflate(R.layout.question_list_row, null);

holder = new ViewHolder();

holder.qeuestion_name = (TextView)vi.findViewById(R.id.qeuestion_name);
holder.img_select_question=(ImageView)vi.findViewById(R.id.img_select_question);
holder.qeuestion_name.setText(question_list.get(position).question);
holder.marks_spinner= (Spinner)vi.findViewById(R.id.marks_spinner);
holder.data = new DataHolder(obj_a);
holder.marks_spinner.setAdapter(holder.data.getAdapter());

if(Global_Application.selected_question_list.contains(question_list.get(position).question_Id))
holder.img_select_question.setVisibility(View.VISIBLE);
else
holder.img_select_question.setVisibility(View.INVISIBLE);


return vi;
}

}


spinner in set custom class

public class DataHolder {


private int selected;
private ArrayAdapter<CharSequence> adapter;

public DataHolder(Context parent) {

adapter = ArrayAdapter.createFromResource(parent, R.array.marks, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}

public ArrayAdapter<CharSequence> getAdapter() {
return adapter;
}

public String getText() {
return (String) adapter.getItem(selected);
}

public int getSelected() {
return selected;
}

public void setSelected(int selected) {
this.selected = selected;
}

}

最佳答案

Try to replace your adapter code with this

public class Question_list_adapter extends BaseAdapter {

private LayoutInflater l_Inflater;
Activity activity;
List<Questions_Details> question_list;

private class ViewHolder {
public TextView qeuestion_name;
public ImageView img_select_question;
public Spinner marks_spinner;
}

public Question_list_adapter(Activity activity,List<Questions_Details> list_question_Details) {
this.activity=activity;
this.question_list =list_question_Details;
}

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

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

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;

if(convertView==null){
holder = new ViewHolder();
convertView = LayoutInflater.from(activity).inflate(R.layout.question_list_row, null);
holder.qeuestion_name = (TextView)convertView.findViewById(R.id.qeuestion_name);
holder.img_select_question=(ImageView)convertView.findViewById(R.id.img_select_question);
holder.marks_spinner= (Spinner)convertView.findViewById(R.id.marks_spinner);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}

holder.qeuestion_name.setText(question_list.get(position).question);
holder.marks_spinner.setAdapter(new DataHolder(activity));
if(Global_Application.selected_question_list.contains(question_list.get(position).question_Id))
holder.img_select_question.setVisibility(View.VISIBLE);
else
holder.img_select_question.setVisibility(View.INVISIBLE);


return convertView;
}

}

关于java - 将 Spinner 包含在 ListView 中后无法单击 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24326482/

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