gpt4 book ai didi

android微调器无法选择项目

转载 作者:行者123 更新时间:2023-11-30 02:24:34 27 4
gpt4 key购买 nike

我有我的自定义基础适配器,我尝试在我的微调器中进行适配。

相对布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="47dp"
android:background="#ffffff" >

<TextView
android:id="@+id/spinnertxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="24dp"
android:text="TextView"
android:textColor="#777777"
android:textSize="17dp" />

<Button
android:id="@+id/button1"
android:layout_width="5dp"
android:layout_height="47dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#00b827" />

</RelativeLayout>

旋转器:

<Spinner
android:id="@+id/pirsaxeobaspinner"
android:layout_width="match_parent"
android:layout_height="47dp"
android:background="@android:color/transparent"
android:drawSelectorOnTop="true"
android:popupBackground="#ffffff" />

基础适配器:

public class CustomSpinnerAdapter extends BaseAdapter {
private Context mContext;
private final ArrayList<String> menu_items_id;
UserHolder holder = null;

// private final int[] Imageid;

private static LayoutInflater inflater = null;

public CustomSpinnerAdapter(Context context, ArrayList<String> names) {
mContext = context;

// this.Imageid = Imageid;
this.menu_items_id = names;
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {

return menu_items_id.size();
}

@Override
public Object getItem(int position) {

return null;
}

@Override
public long getItemId(int position) {

return 0;
}

@SuppressLint("ViewHolder")
@Override
public View getView(int position, View convertView, ViewGroup parent) {

View row = convertView;
holder = new UserHolder();

if (row == null) {
holder = new UserHolder();
row = inflater.inflate(R.layout.custom_spinner_adapter, null);

holder.textView = (TextView) row.findViewById(R.id.spinnertxt);

} else {
holder = (UserHolder) row.getTag();
}

holder.textView.setText(menu_items_id.get(position));


row.setTag(holder);

return row;
}

public class UserHolder {

public TextView textView;

}

}

主要java代码:

public class MyFragment extends Fragment {
public final static String TAG = MyFragment.class.getSimpleName();

private Spinner pirsaxeobaspinner;
private ArrayList<String> custom_adapter;
private CustomSpinnerAdapter my_adapter;

public static MyFragment newInstance() {
return new MyFragment();
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.ganayopiereba_fragment, container,
false);
pirsaxeobaspinner=(Spinner)rootView.findViewById(R.id.pirsaxeobaspinner);
custom_adapter=new ArrayList<String>();
custom_adapter.add("Door");
custom_adapter.add("Home");



my_adapter=new CustomSpinnerAdapter(getActivity(), custom_adapter);
pirsaxeobaspinner.setAdapter(my_adapter);

pirsaxeobaspinner.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub

}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub

}
});



return rootView;
}
}

我可以在 Spinner 中调整我的 ArrayList,但是我无法从 ArrayList 中选择项目。

最佳答案

你需要改变这个:

@Override
public Object getItem(int position) {

return menu_items_id.get(position);
}

@Override
public long getItemId(int position) {

return position;
}

关于android微调器无法选择项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28048652/

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