按我的客户要求我在下面做编码的了解,所以请检查它,希望它会帮助你。
首先在你的活动实施听者
public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener
现在你的XML文件应该如下面
activity_main.xml中
<LinearLayout
android:id="@+id/main_Layout"
android:background="#FF0000"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/scMainView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/llSpinnerSection"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</ScrollView>
</LinearLayout>
现在在主AC tivity声明布局如下
LinearLayout mainSpinnerLayout = (LinearLayout) findViewById(R.id.llSpinnerSection);
立即创建一个方法获取数据,并设置微调
public void createSpinners()
{
final DataHelper db = new DataHelper(getApplicationContext());
final List<String> labelKolom = db.getKolom();
spnKolom = new Spinner[labelKolom.size()];
for (int itung=0;itung<labelKolom.size();itung++)
{
spnKolom[itung] = new Spinner(this);
spnKolom[itung].setTag(itung);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, labelKolom);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnKolom[itung].setAdapter(spinnerArrayAdapter);
spnKolom[itung].setOnItemSelectedListener(this);
if(itung == 0)
{
spnKolom[itung].setVisibility(View.VISIBLE);
}
else
{
spnKolom[itung].setVisibility(View.GONE);
}
mainSpinnerLayout.addView(spnKolom[itung]);
}
}
终于实现方法对于微调器,以显示对项目选择下一步微调
//Performing action onItemSelected and onNothing selected
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position,long id) {
if(position < spnKolom.length - 1)
{
spnKolom[position + 1].setVisibility(View.VISIBLE);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
何PE这将为你工作
你的纺纱总人数是否是固定的?意味着您想要动态创建多少个旋转器? – Vickyexpert
与http:// stackoverflow类似。com/a/39405348/2826147 –
@Vickyexpert总旋转器跟在我的数据库中的列数。所以纺纱厂的数量不固定。 –