gpt4 book ai didi

android - 如何为超过 1 个微调器设置 setOnClickListener

转载 作者:行者123 更新时间:2023-11-29 16:12:16 25 4
gpt4 key购买 nike

Actually i got a value in server to create the spinner. i tried to set setOnClickListener for all spinners but it getting error.Refer my code below.

public static Spinner[] clickspin = new Spinner[nvalue];//nvalue = 2 (get from server)
for(int i=0;i<nvalue;i++)
{
clickspin[i]=new Spinner(this);
clickspin[i].setLayoutParams(new TableRow.LayoutParams(90/*length of combo box*/, TableRow.LayoutParams.WRAP_CONTENT));
clickspin[i].setAdapter(adapter1);
clickspin[i].setId(i);
clickspin[i].setClickable(true);
clickspin[i].setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
int n = v.getId();

}
});
}

how to set setOnClickListener for every spinner

最佳答案

对于微调器,我们使用 OnItemSelectedListener .

clickspin[i].OnItemSelectedListener(new AdapterView.OnItemSelectedListener() {               

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}

public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
});

参见 Spinners guide .

关于android - 如何为超过 1 个微调器设置 setOnClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12191668/

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