Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.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
Java 如何在RecyclerView中为行布局充气?_Java_Android_Android Recyclerview_Tablelayout_Textwatcher - Fatal编程技术网

Java 如何在RecyclerView中为行布局充气?

Java 如何在RecyclerView中为行布局充气?,java,android,android-recyclerview,tablelayout,textwatcher,Java,Android,Android Recyclerview,Tablelayout,Textwatcher,我想做两件事: 1) 用回收器视图替换我的动态表格布局。 2) 计算所选项目的总数 这是我当前的代码 private void showItem(String json) { String itembarcode = ""; String itemdesc = ""; String weight = ""; String rate = ""; String making = ""; String netrate = ""; String total = ""; try { JSONO

我想做两件事: 1) 用回收器视图替换我的动态表格布局。 2) 计算所选项目的总数

这是我当前的代码

private void showItem(String json) {
String itembarcode = "";
String itemdesc = "";
String weight = "";
String rate = "";
String making = "";
String netrate = "";
String total = "";


try {
    JSONObject jsonObject = new JSONObject(json);
    JSONArray result = jsonObject.getJSONArray(ParseBarcode.JSON_ARRAY);
    JSONObject itemData = result.getJSONObject(0);
    itembarcode = itemData.getString(ParseBarcode.KEY_BARCODE);
    itemdesc = itemData.getString(ParseBarcode.KEY_DESC);
    weight = itemData.getString(ParseBarcode.KEY_WEIGHT);
    rate = itemData.getString(ParseBarcode.KEY_RATE);
    making = itemData.getString(ParseBarcode.KEY_MAKING);
    netrate = itemData.getString(ParseBarcode.KEY_NETRATE);
    total = itemData.getString(ParseBarcode.KEY_TOTAL);
} catch (JSONException e) {
    e.printStackTrace();
}


//table started

TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f);
rowParams.setMargins(16, 0, 16, 0);

TableLayout tableLayout = new TableLayout(AddInvEst.this);
tableLayout.setLayoutParams(tableParams);

TableRow newRow = new TableRow(AddInvEst.this);
newRow.setLayoutParams(tableParams);

barCode = new TextView(AddInvEst.this);
barCode.setLayoutParams(rowParams);
barCode.setGravity(Gravity.CENTER);

itemDesc = new TextView(AddInvEst.this);
itemDesc.setLayoutParams(rowParams);
itemDesc.setGravity(Gravity.CENTER);

weightLine = new TextView(AddInvEst.this);
weightLine.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 0.75f));
weightLine.setGravity(Gravity.CENTER);

rateAmount = new EditText(AddInvEst.this);
rateAmount.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 0.5f));
rateAmount.setGravity(Gravity.CENTER);
rateAmount.addTextChangedListener(rateTextWatcher);

makingAmount = new EditText(AddInvEst.this);
makingAmount.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 0.5f));
makingAmount.setGravity(Gravity.CENTER);
makingAmount.addTextChangedListener(mkAmountTextWatcher);

netRate = new TextView(AddInvEst.this);
netRate.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 0.5f));
netRate.setGravity(Gravity.CENTER);
netrates.add(netrate);

itemtotal = new TextView(AddInvEst.this);
itemtotal.setLayoutParams(rowParams);
itemtotal.setGravity(Gravity.CENTER);
totals.add(total);

double[] doubleList = new double[totals.size()];
double sum = 0;
for (int i = 0; i < totals.size(); ++i) {
    doubleList[i] = Double.parseDouble(totals.get(i));
    sum += doubleList[i];
}

barCode.setText(itembarcode);
itemDesc.setText(itemdesc);
weightLine.setText(weight);
rateAmount.setText(rate);
makingAmount.setText(making);
netRate.setText(netrate);
itemtotal.setText(total);
textViewSum.setText(sum * (0.02) + sum + "");//set total text to sum
textViewVat.setText(sum * (0.02) + "");

newRow.addView(barCode);
newRow.addView(itemDesc);
newRow.addView(weightLine);
newRow.addView(rateAmount);
newRow.addView(makingAmount);
newRow.addView(netRate);
newRow.addView(itemtotal);
itemTable.addView(newRow);

按照您喜欢的表格布局方式进行行布局。然后在回收器中充气view@ParthAnjaria你能举个例子吗?@ParthAnjaria我们能把视图添加到回收视图中吗?你能指定你能做一个你想做的行的布局吗。然后充气
    private void calculateAndShow(double wt, double rt, double mk) {
    String w = weightLine.getText().toString();
    wt = Double.parseDouble(w);
    double NetRate = (double) Math.round((rt + mk) * 100.0) / 100.0;
    double Total = (double) Math.round(((NetRate / 10) * wt) * 100.0) / 100.0;

    netRate.setText(NetRate + "");
    itemtotal.setText(Total + "");
}

private TextWatcher rateTextWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        String rate = rateAmount.getText().toString();
        rt = Double.parseDouble(rate);
        calculateAndShow(wt, rt, mk);
        rates.add(rate);
    }
};

private TextWatcher mkAmountTextWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        String mkAmt = makingAmount.getText().toString();
        mk = Double.parseDouble(mkAmt);
        calculateAndShow(wt, rt, mk);
        mkCharges.add(mkAmt);

    }
};