dimanche 31 janvier 2016

Android Text displayed on TextView is not coming properly from SQLite

Using this Java class to print data retrieved from SQLite db.
We just need to enter data in an Edittext and then print it back to a TextView.
However the display is not corect , please refer attached code.

package maptest.com.mapstest;

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.view.MenuItem;

public class userdetails extends Activity implements View.OnClickListener {

EditText username;
TextView username1;
    TextView try2;

    dbdetails db1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_userdetails2);

        username = (EditText) findViewById(R.id.username);
        username1 = (TextView) findViewById(R.id.username1);
        username.getText().clear();
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        username.setText("");
    }

    public void adddetails(View view){
        db1 = new dbdetails(this);
        user user = new user(username.getText().toString());
        db1.userdetails1(user);
        printdb();
                }
    public void printdb(){
        String dbst = db1.dbtostring();
        username1.setText(dbst);
username.getText().clear();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_userdetails, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

enter image description here

Aucun commentaire:

Enregistrer un commentaire