Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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 通过相乘更改一个textview的值,同时更改其他textview的值_Android_Parsing_Valuechangelistener - Fatal编程技术网

Android 通过相乘更改一个textview的值,同时更改其他textview的值

Android 通过相乘更改一个textview的值,同时更改其他textview的值,android,parsing,valuechangelistener,Android,Parsing,Valuechangelistener,在这里,我从一个URL获取解析数据,现在我试图在文本视图中动态地将解析数据的值更改为用户,我的代码是 public class Main extends ListActivity { EditText resultTxt; public double C_webuserDouble; public double C_cashDouble; public double C_transferDouble; public double S_webuserD

在这里,我从一个URL获取解析数据,现在我试图在文本视图中动态地将解析数据的值更改为用户,我的代码是

public class Main extends ListActivity {

    EditText resultTxt;

    public double C_webuserDouble;
    public double C_cashDouble;
    public double C_transferDouble;

    public double S_webuserDouble;
    public double S_cashDouble;
    public double S_transferDouble;

    TextView cashTxtView;
    TextView webuserTxtView;
    TextView transferTxtView;
    TextView S_cashTxtView;
    TextView S_webuserTxtView;
    TextView S_transferTxtView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listplaceholder);
        cashTxtView = (TextView) findViewById(R.id.cashTxtView);
        webuserTxtView = (TextView) findViewById(R.id.webuserTxtView);
        transferTxtView = (TextView) findViewById(R.id.transferTxtView);

        S_cashTxtView = (TextView) findViewById(R.id.S_cashTxtView);
        S_webuserTxtView = (TextView) findViewById(R.id.S_webuserTxtView);
        S_transferTxtView = (TextView) findViewById(R.id.S_transferTxtView);

        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        JSONObject json = JSONfunctions
                .getJSONfromURL("http://ldsclient.com/ftp/strtojson.php");

        try {

            JSONArray netfoxlimited = json.getJSONArray("netfoxlimited");

            for (inti = 0; i < netfoxlimited.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                JSONObject e = netfoxlimited.getJSONObject(i);

                map.put("date", e.getString("date"));
                map.put("c_web", e.getString("c_web"));
                map.put("c_bank", e.getString("c_bank"));
                map.put("c_cash", e.getString("c_cash"));
                map.put("s_web", e.getString("s_web"));
                map.put("s_bank", e.getString("s_bank"));
                map.put("s_cash", e.getString("s_cash"));
                mylist.add(map);
            }
        } catch (JSONException e) {
            Log.e("log_tag", "Error parsing data " + e.toString());
        }

        ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.main,
                new String[] { "date", "c_web", "c_bank", "c_cash", "s_web",
                        "s_bank", "s_cash", }, new int[] { R.id.item_title,
                        R.id.webuserTxtView, R.id.transferTxtView,
                        R.id.cashTxtView, R.id.S_webuserTxtView,
                        R.id.S_transferTxtView, R.id.S_cashTxtView });

        setListAdapter(adapter);

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                @SuppressWarnings("unchecked")
                HashMap<String, String> o = (HashMap<String, String>) lv
                        .getItemAtPosition(position);
                Toast.makeText(Main.this,
                        "ID '" + o.get("id") + "' was clicked.",
                        Toast.LENGTH_SHORT).show();

            }
        });
        resultTxt = (EditText) findViewById(R.id.editText1);
        resultTxt.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                resultTxt.setText("");
            }
        });
        resultTxt.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub

                String text;
                text = resultTxt.getText().toString();
                if (resultTxt.getText().length() > 5) {
                    calculateSum(C_webuserDouble, C_cashDouble,
                            C_transferDouble);
                    calculateSunrise(S_webuserDouble, S_cashDouble,
                            S_transferDouble);
                } else {

                }
            }

            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub

            }

        });
    }

    private void calculateSum(Double webuserDouble, Double cashDouble,
            Double transferDouble) {

        String Qty;
        Qty = resultTxt.getText().toString();

        if (Qty.length() > 0) {
            double QtyValue = Double.parseDouble(Qty);
            double cashResult;
            double webuserResult;
            double transferResult;

            cashResult = cashDouble * QtyValue;
            webuserResult = webuserDouble * QtyValue;
            transferResult = transferDouble * QtyValue;

            DecimalFormat df = new DecimalFormat("#.##");
            String cashResultStr = df.format(cashResult);
            String webuserResultStr = df.format(webuserResult);
            String transferResultStr = df.format(transferResult);

            cashTxtView.setText(String.valueOf(cashResultStr));
            webuserTxtView.setText(String.valueOf(webuserResultStr));
            transferTxtView.setText(String.valueOf(transferResultStr));

            // cashTxtView.setFilters(new InputFilter[] {new
            // DecimalDigitsInputFilter(2)});

        }

        if (Qty.length() == 0) {
            cashTxtView.setText(String.valueOf(cashDouble));
            webuserTxtView.setText(String.valueOf(webuserDouble));
            transferTxtView.setText(String.valueOf(transferDouble));

        }

    }

    private void calculateSunrise(Double webuserDouble, Double cashDouble,
            Double transferDouble) {

        String Qty;
        Qty = resultTxt.getText().toString();

        if (Qty.length() > 0) {
            double QtyValue = Double.parseDouble(Qty);
            double cashResult;
            double webuserResult;
            double transferResult;

            cashResult = cashDouble * QtyValue;
            webuserResult = webuserDouble * QtyValue;
            transferResult = transferDouble * QtyValue;

            DecimalFormat df = new DecimalFormat("#.##");
            String cashResultStr = df.format(cashResult);
            String webuserResultStr = df.format(webuserResult);
            String transferResultStr = df.format(transferResult);

            S_cashTxtView.setText(String.valueOf(cashResultStr));
            S_webuserTxtView.setText(String.valueOf(webuserResultStr));
            S_transferTxtView.setText(String.valueOf(transferResultStr));
        }

        if (Qty.length() == 0) {
            S_cashTxtView.setText(String.valueOf(cashDouble));
            S_webuserTxtView.setText(String.valueOf(webuserDouble));
            S_transferTxtView.setText(String.valueOf(transferDouble));

        }

    }
}

确保布局文件包含id为list的ListView。这是ListActivity的必备功能

<ListView android:id="@android:id/list"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="#00FF00"
           android:layout_weight="1"
           android:drawSelectorOnTop="false"/>

点击查看


在onCreateView中设置setListAdapter之前,检查getListView()是否返回null。

发布logcat输出的其余部分。它将显示空点出现的位置。@Cdr。鲍威尔:你是怎么编辑的?我试了很多次,但都没办法修改。thanx@sur007这里的问题是“ResultText=(EditText)findViewById(R.id.editText1);”如果您的EditText ResultText的值为null,请在每行前面放置4个空格进行检查。不知道撇号是否也有用,但我又懒又困,所以这对我来说已经足够了{t是111代码,然后wat是解决方案?ny idea??oncreateview中的某些内容为空,您需要找到它以进行修复。尝试在调试模式下运行应用程序,然后按F6遍历oncreate视图的每一行
<ListView android:id="@android:id/list"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="#00FF00"
           android:layout_weight="1"
           android:drawSelectorOnTop="false"/>