store an EditText value into SQLite database line by line

i made an EditText that displayed value with multiple line like this...

i want to keep that value in a SQLite database. this is the code i use:

export.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            final View export_layout = getLayoutInflater().inflate(R.layout.export_layout, null);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    MainActivity.this);
            builder.setView(export_layout);
            builder.setTitle("Input new DB");
            builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                        int which) {
                    editText1 = (EditText) export_layout.findViewById(R.id.editText1);
                    String table = editText1.getText().toString();
                    String val = textStatus.getText().toString();
                    db.execSQL("create table "+table+"(ANY text)");
                    db.execSQL("insert into "+table+" values('"+val+"')");
                }
            });
            builder.setNegativeButton("back",
                    new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog,
                        int which) {
                    dialog.dismiss();
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

TextStatus is an EditText where the value is displayed like the image above. editText1 is where the user input the table name.

the problem is when i save the value, the whole value is inserted into one cell. i want the value to be separated per line then inserted into a single cell for each line.

is there any way to do that?

edit: this is how i set the text in TextStatus:

x = new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context c, Intent intent) 
        {
            results = wifi.getScanResults();
            size = results.size();
            if (size > 0) {
                for (int i=0; i<size; i++){
                    ScanResult scanresult = wifi.getScanResults().get(i);
                    String ssid = scanresult.SSID;
                    int rssi = scanresult.level;
                    String bssid = scanresult.BSSID;
                    String rssiString = String.valueOf(rssi);
                    textStatus.append(ssid + "," + bssid + "," + rssiString + "\n");
                }
                unregisterReceiver(x); //stops the continuous scan
                textStatus.append("------------"+j+"\n");
                j++;
            } 
        }
    };

Answers


Try Scanner:

Scanner scanner = new Scanner(val);
while (scanner.hasNextLine()) {
    String line = scanner.nextLine();
    //Insert the line here
}

Update: This is how it should looks like in your codes

editText1 = (EditText) export_layout.findViewById(R.id.editText1);
String table = editText1.getText().toString();
String val = textStatus.getText().toString();
db.execSQL("create table "+table+"(ANY text)");
Scanner scanner = new Scanner(val);
while (scanner.hasNextLine()) {
    String line = scanner.nextLine();
    db.execSQL("insert into "+table+" values('"+line+"')");
}

Need Your Help

python 2 - why does 'with' behave differently in embedded c code?

python c++

I'm trying to use python 2.7.5 in a c/c++ DLL. This DLL is used by another application which has made debugging a challenge. After banging away at this for hours I have isolated the problem down to...

MySQL alter table and convert data from text to datetime

mysql sql date datetime

I have a table with a column date but it is stored as text.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.