-1

I want to get input from edittext in an array which will be seperated by comma(,) and compare its values to multiple textviews and change their backgrounds.I used split command but its not working.I'm a newbie,thanks in advance. My code is:

enter code here
    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
            textView1 =(TextView)findViewById(R.id.textView1);
            textView2 =(TextView)findViewById(R.id.textView2);
            textView3 =(TextView)findViewById(R.id.textView3);
            textView4 =(TextView)findViewById(R.id.textView4);
            editText1 =(EditText)findViewById(R.id.editText1);
            button1 =(Button)findViewById(R.id.button1);
            String value = editText1.getText().toString();
            String[] floatStrings = value.split(",");
            int[] result = new int[floatStrings.length];
            for (int i=0; i<5; i++)
            {
                result[i] = Integer.valueOf(floatStrings[i]);
            }   

                 {
                        if(result[1]<30)
                        {
                            textView1.setBackgroundColor(Color.BLUE);
                        }

                        else if(result[2]>45)
                        {
                            textView2.setBackgroundColor(Color.RED);
                        }
                        else if(result[3]==50)
                        {
                            textView3.setBackgroundColor(Color.DKGRAY);
                        }

                        }



        return; 
            }

}

  • What do you mean by not working? Please add you logcat error trace. – Rohit5k2 Feb 18 '15 at 07:24
  • I don't have any error but the application crashes while opening. – Gokul Ramanan Feb 18 '15 at 08:26
  • You mean to say app is crashing and there isn't anything in logcat? – Rohit5k2 Feb 18 '15 at 08:33
  • yes,"Unfortunately app is stopped" in emulator.I just want some help in frame the code to get input from edittext in an array which will be separated by comma(,) and compare its values to multiple textviews background colors.Look at above code which i tried myself. – Gokul Ramanan Feb 18 '15 at 09:01
  • That's not the point. If app is crashing then there should be something in logcat. – Rohit5k2 Feb 18 '15 at 09:03

1 Answers1

0

You need to use this in order to split a comma separated string your_string.split("\.") Take a look at the link below. This is the case of '.', same applies for you

Java string split with "." (dot)

Community
  • 1
  • 1
Prateek Thakur
  • 179
  • 1
  • 5