简体   繁体   中英

save Multiline EditText in sqlite

I am trying to work with Strings in an sqlite database. I am planning to save Multiline EditText into sqlite VARCHAR column Does anyone know a way to do it?

Every time I use EditText.getText().toString() I got only one line

For example,

            <EditText
            android:id="@+id/edittext"
            android:layout_width="267dp"
            android:layout_height="73dp"
            android:inputType="textCapSentences|textMultiLine" 
            android:singleLine="false" >

When i entered

abc
123
iiiiii

edittext.getText().toString() ONLY return "abc" !!!!

How can I save all the text into sqlite VARCHAR column?

You will need to post more of your code, in order for us to see what is happening. Take this minimalistic app:

public class Example extends Activity implements OnClickListener {
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onClick(View view) {
        //      Find the TextView,      set it's text from       the EditText
        ((TextView) findViewById(R.id.text)).setText(((EditText) findViewById(R.id.edit)).getText());
    }   
}

Paired with this xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="onClick" />

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

At the click of a button, this bare-bones app fulfills your requirements of reading a multiline EditText and passing its contents to another object. In this case we pass the string to a TextView, the code for a database is fundamentally the same. It even copies the color of the "unknown word" highlighting:

屏幕截图

(Don't expect that to copy the color highlighting so easily to a database and back.) So this is why I ask for a real selection of your code, because you are altering something in this process and I can't see the error from here.

Please use the Edit feature of your question to post the appropriate functions where you: read the EditText, store its contents in the database and retrieve it at a later point.

edittext = (EditText) findViewById(R.id.multitext); 
str=edittext.getText().toString()                           
DBHelper req_task = new DBHelper(Send_req.this);
req_task.createDataBase();
req_task.openDataBase();
req_task.writetext(str);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM