3

在列表视图中,单个列表项中有文本视图、按钮和编辑文本。所有项目都是动态生成的,有时 3 有时 7 有时 14 ...

如果我在那些edittext中输入值......我可以设置6或更少edittext的值......在屏幕上可见项目的4.7“设备Genymotion是6和7th部分......而在10”genymotin , 可见项目为 9

如何从此动态列表视图中的所有编辑文本中获取值?

......

public class DeliveryDetailFinal extends BaseFragment {

    Integer mPickingId = null;
    Integer mLineSize = null;
    LinkedHashMap<String, String> productData = new LinkedHashMap<String, String>();
    List<Object> moveLinesfinalData;
    View mDOViewFinal = null;
    ListView mMoveLinesFinalListDo = null;
    Context mDBContextDDF = null;
    List<OEDataRow> moveLinesData;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        mDOViewFinal = inflater.inflate(R.layout.fragment_delivery_order_detail_final_view,
                container, false);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mLineSize = bundle.getInt("lineSize");
        }
        init();
        mDODHelper = db().getOEInstance();
        mDBContextDDF = (Context) getActivity();
        return mDOViewFinal;
    }

    private void init(){
            initControls();
    }

    private void initControls(){
        moveLinesData = mDeliveryOrderData.getO2MRecord("move_lines").browseEach();
        mMoveLinesFinalListDo = (ListView) mDOViewFinal.findViewById(R.id.DOMoveLinesFinal);
        moveLinesfinalData = new ArrayList<Object>();
        moveLinesfinalData.addAll(moveLinesData);
        OEListAdapter listAdapter = new OEListAdapter(mDBContextDDF, R.layout.fragment_final_details_view, moveLinesfinalData){
            @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                  View mView = convertView;
                  if (mView == null)
                      mView = getActivity().getLayoutInflater().inflate(
                              getResource(), parent, false);
                  mView = createListViewRow(mView, position, moveLinesfinalData); 
                  mView.setVisibility(1);
                  return mView;
              }
        };
        mMoveLinesAdapterfinal = listAdapter;
        Log.d("final", "final  mMoveLinesAdapterfinal "+mMoveLinesAdapterfinal);
        mMoveLinesFinalListDo.setAdapter(mMoveLinesAdapterfinal);
    }

    public View createListViewRow(View mView, int position,
            List<Object> moveLinesObjectData) {
            final OEDataRow row = (OEDataRow) moveLinesObjectData.get(position);
        TextView eProductName = (TextView) mView.findViewById(R.id.textViewProductNameFinal);
        eProductName.setText(row.getString("name").toString());
        LinearLayout innerLinearLayout = (LinearLayout) mView.findViewById(R.id.innerLinearLayout);
        EditText editTextProductId = (EditText) innerLinearLayout.findViewById(R.id.editTextProductId);
        if(row != null)
            editTextProductId.setText(row.getInt("id").toString());

        EditText eProductSerial = (EditText) innerLinearLayout.findViewById(R.id.editTextProductSerialFinal);

        String id = editTextProductId.getText().toString();
        String serialNumber = ((EditText) eProductSerial).getText().toString();
        productData.put(id,serialNumber);

        Log.d("final", "final productData before "+productData);
        eProductSerial.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            public void onFocusChange(View v, boolean hasFocus) {
               if (!hasFocus)
                {
                    LinearLayout parentLayout = (LinearLayout) v.getParent();
                    if(parentLayout != null) {
                        EditText editTextProductIdFocus = (EditText) parentLayout.findViewById(R.id.editTextProductId);
                        String id = editTextProductIdFocus.getText().toString();
                        String serialNumber = ((EditText) v).getText().toString();
                        productData.put(id,serialNumber);
                    }
                }
            }
        });
            final Button BarCode = (Button) innerLinearLayout.findViewById(R.id.buttonBarcode);
            BarCode.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.getId();
                }
            });
        return mView;
    }

    @Override
    public Object databaseHelper(Context context) {
        return new StockPickingDB(context);
    }

}

......

......

fragment_delivery_order_detail_final_view.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="55dp"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/DOMoveLinesFinal"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>
</LinearLayout>

fragment_final_details_view.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayoutID"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="3dp"
    android:orientation="vertical"
    android:padding="2dp"
    android:visibility="visible" >

            <TextView
                android:id="@+id/textViewProductNameFinal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginLeft="3dp"
                android:layout_marginStart="3dp"
                android:text="@string/product"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:visibility="visible">
                <requestFocus />
            </TextView>

        <LinearLayout
            android:id="@+id/innerLinearLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="1dp"
            android:layout_margin="1dp"
            android:orientation="horizontal"
            android:visibility="visible">

            <Button
                android:id="@+id/buttonBarcode"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/barcode"
                android:visibility="visible" />

            <EditText
                    android:id="@+id/editTextProductId"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/serial_no"
                    android:visibility="gone">
            </EditText>

            <EditText
                android:id="@+id/editTextProductSerialFinal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/serial_no"
                android:visibility="visible">
            </EditText>
    </LinearLayout>
</LinearLayout>

请帮助我...提前谢谢...

4

1 回答 1

1

我已经通过使用查看器概念解决了这个问题。

于 2014-12-20T02:42:47.020 回答