我的片段中有一个微调器。我希望当我点击微调器中的任何位置时,微调器视图应该接近并且微调器文本应该根据我的选择而改变。我的情况我必须在旋转器之外关闭它,它的文本保持不变。
public SmsBatchSpinnerListAdapter(Context context, BaseActivity activity,
ArrayList<String> student, ArrayList<String> studentId, ArrayList<String>
updatedSmsNumber, ArrayList<String> updatedUserId)
{
super(context, R.layout.sms_batchname_spinner, stBatch);
this.student = student;
this.studentId = studentId;
this.context = context;
this.activity = activity;
this.updatedUserId = updatedUserId;
this.updatedSmsNumber = updatedSmsNumber;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}
private View getCustomView(final int position, View convertView, final ViewGroup parent) {
String name;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.sms_batchname_spinner, parent, false);
final LinearLayout linearLayout = (LinearLayout) ((Activity) context).findViewById(R.id.hiddenlayout);
studentBatch = (TextView) convertView.findViewById(R.id.text1);
studentBatch.setTag(position);
name = student.get(position);
spinner = (Spinner) ((Activity)context).findViewById(R.id.spinner);
studentBatch.setText(name);
studentBatch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String idIndex = studentId.get(position);
if(!idIndex.equals("0")){
linearLayout.setVisibility(view.VISIBLE);
getStudentName(studentId.get(position));
}
else{
//Toast.makeText(context,"Please select an item ",Toast.LENGTH_SHORT).show();
}
}
});
return convertView;
}
答案 0 :(得分:0)
我确定,没有spinner
存在关闭自己的方法
和,
我认为studentBatch.setOnClickListener(...)
是阻止微调器关闭的方法。相反,您可以将setOnItemSelectedListener(..)
设置为微调器以在选择微调器项时获取事件,这也将关闭您的微调器(系统行为类型)。
此外,
spinner.setSelection(int position)
可以做到这一点。
即
studentBatch.setOnClickListener(....) {
spinner.setSelection(position);
}
答案 1 :(得分:0)
使用setAdapter方法将arraylist绑定到微调器。您将在微调器中获取所选项目,对话将消失。