I am trying to change the value of one editview while there is change in another editview even if the program runs value is not passed to editview.Value is passes from one edit view to another and then the value is multiplied by parsed value. help my main activity code is:
public class Main extends ListActivity {
public double C_webuserDouble;
public double C_cashDouble;
public double C_transferDouble;
public double S_webuserDouble;
public double S_cashDouble;
public double S_transferDouble;
EditText resultTxt ;
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);
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(int i=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);
/** C_webuserDouble=json.getDouble("c_web");
C_transferDouble= json.getDouble("c_bank");
C_cashDouble=json.getDouble("c_cash");
S_webuserDouble=json.getDouble("s_web");
S_transferDouble= json.getDouble("s_bank");
S_cashDouble=json.getDouble("s_cash");*/
}
}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);
resultTxt = (EditText) findViewById(R.id.editText1);
resultTxt.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
String text;
text=resultTxt.getText().toString();
if(resultTxt.getText().length()>0){
calculateSum(C_webuserDouble,C_cashDouble,C_transferDouble);
calculateSunrise(S_webuserDouble,S_cashDouble,S_transferDouble);
}
}
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// 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));
}
}
}
Following is my listplaceholder code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
<TextView
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="No data"/>
</LinearLayout>
all the code are same but following logcat error generates when user input is given
08-29 14:53:01.234: E/AndroidRuntime(2206): Uncaught handler: thread main exiting due to uncaught exception
08-29 14:53:01.245: E/AndroidRuntime(2206): java.lang.NullPointerException
08-29 14:53:01.245: E/AndroidRuntime(2206): at com.mokshya.jsonnetfoxtab.Main.calculateSum(Main.java:142)
08-29 14:53:01.245: E/AndroidRuntime(2206): at com.mokshya.jsonnetfoxtab.Main.access$0(Main.java:120)
08-29 14:53:01.245: E/AndroidRuntime(2206): at com.mokshya.jsonnetfoxtab.Main$1.afterTextChanged(Main.java:101)
Change your xml to that