Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:在ListView中启用最后一个微调器并禁用其余微调器。_Android_Android Listview_Android Spinner - Fatal编程技术网

Android:在ListView中启用最后一个微调器并禁用其余微调器。

Android:在ListView中启用最后一个微调器并禁用其余微调器。,android,android-listview,android-spinner,Android,Android Listview,Android Spinner,我正在使用自定义列表视图,其中有一个微调器 代码:- <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:ba

我正在使用自定义列表视图,其中有一个微调器

代码:-

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/lightGray2"
    android:shrinkColumns="*"
    android:stretchColumns="*" >

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Spinner
            android:id="@+id/spinnerPaymentType"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="17" />

        <EditText
            android:id="@+id/eTextPaymentAmount"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="7"
            android:inputType="number" />

        <Button
            android:id="@+id/btnPaymentDetail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="6" />
    </TableRow>
</TableLayout>

有一个按钮(假设buttonA)位于ListView的外侧,单击该按钮后,会在ListView中添加一行

现在我想在单击按钮时禁用所有其他行微调器

假设已经有三行了,在ListView中添加第四行之前,我想禁用前三行中的微调器

适配器getView代码:-

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    System.out.println("*** getView() ***");
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(rowResourceId, parent, false);

    Spinner spinnerPaymentType = (Spinner) rowView
            .findViewById(R.id.spinnerPaymentType);
    EditText eTextPaymentAmount = (EditText) rowView
            .findViewById(R.id.eTextPaymentAmount);
    eTextPaymentAmount.setText(String.valueOf(position));
    btnPaymentDetail = (Button) rowView.findViewById(R.id.btnPaymentDetail);
    btnPaymentDetail.setTag(position);
    btnPaymentDetail.setOnLongClickListener(this);

    btnPaymentDetail.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            System.out.println("*** btnPaymentDetail is clicked");
            getPaymentDetail();
        }
    });

    ArrayList<PaymentType> aListpaymentTypes = new ArrayList<PaymentType>();
    for (int i = 0; i < paymentCollection.get(0).getaListPaymentOptions()
            .size(); i++) {
        aListpaymentTypes.add(new PaymentType(paymentCollection.get(0)
                .getaListPaymentOptions().get(i).getIntPaymentId(),
                paymentCollection.get(0).getaListPaymentOptions().get(i)
                        .getStrPaymentType()));
    }
    ArrayAdapter<PaymentType> aAdapterPaymentType = new ArrayAdapter<PaymentType>(
            context, android.R.layout.simple_spinner_item,
            aListpaymentTypes);
    aAdapterPaymentType
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerPaymentType.setAdapter(aAdapterPaymentType);
    spinnerPaymentType.setOnItemSelectedListener(this);
    return rowView;
}
@覆盖
公共视图getView(int位置、视图转换视图、视图组父视图){
System.out.println(“***getView()***”);
LayoutFlater充气器=(LayoutFlater)上下文
.getSystemService(上下文布局\充气机\服务);
查看rowView=充气器。充气(rowResourceId,父项,false);
微调器微调器PaymentType=(微调器)行视图
.findViewById(R.id.spinnerPaymentType);
EditText eTextPaymentAmount=(EditText)行视图
.findViewById(R.id.eTextPaymentAmount);
eTextPaymentAmount.setText(String.valueOf(position));
btnPaymentDetail=(按钮)rowView.findviewbyd(R.id.btnPaymentDetail);
btnPaymentDetail.setTag(位置);
btnPaymentDetail.setOnLongClickListener(这个);
btnPaymentDetail.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
System.out.println(“***点击btnPaymentDetail”);
getPaymentDetail();
}
});
ArrayList aListpaymentTypes=新ArrayList();
对于(int i=0;i
我猜您是在ArrayAdapter的
getView()
方法中扩展此布局。在该方法中,可以检查当前列表项是否是最后一个列表项,如果不是,则禁用微调器。添加新项时,请使ArrayAdapter无效,以便重新绘制列表

更新

在返回rowView之前尝试添加此行:

//if spinner is last spinner, enable. Otherwise disbale.
spinnerPaymentType.setEnabled( (position == this.getCount()-1) );

@我知道代码将在getView方法中。如何禁用微调器。要禁用微调器,请编写
spinner.setEnabled(false)
。如果可以粘贴getView()方法,我可以告诉您如何执行此操作?我更新并添加了getView方法。。