jeudi 28 janvier 2016

Android sqlite data to new activity

I have a problem regarding, getting the data to a new activity from the Mainacitivy. Right now im just getting the data out in a Maketoast and it works fine, but when im starting an intent, im missing the overview.

//my buttonclicker which get the toast message, and starting the intent
//at the top i have an edit text and the whole code is in MainActivity
    final EditText et1=(EditText)findViewById(R.id.editText1);
//and a button
    final Button b1=(Button) findViewById(R.id.button1);

//display contact
        private void DisplayContact(Cursor c)
        {
            // TODO Auto-generated method stub
            Toast.makeText(getBaseContext(),"id: " + c.getString(0) + "\n" +"Name: " + c.getString(1) + "\n" +
            "Email: " + c.getString(2),
                    Toast.LENGTH_LONG).show();
        }


    });


    b3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            db.open();
            Bundle dataBundle = new Bundle();

       Intent intent = new Intent(MainActivity.this, DisplayCv.class);

            Cursor c = db.getContact(Integer.parseInt
                    (et1.getText().toString()));
            if (c.moveToFirst())

                DisplayContact(c);

            startActivity(intent);


            db.close();
            }

//My display cv activity, im not quite sure what to do here, much of the code
  isn´t used, just searching for a some simple example to get the name out.

  public class DisplayCv extends Activity {
private DBAdapter mydb;

TextView navn;
TextView telefon;
TextView email;
TextView addresse;
TextView bynavn;
TextView sendemail;
int id_To_Update = 0;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
    //super referer til parent constructor
    super.onCreate(savedInstanceState);
    setContentView(R.layout.displaycv);

    navn = (TextView) findViewById(R.id.editTextName);
    telefon = (TextView) findViewById(R.id.editTextPhone);
    email = (TextView) findViewById(R.id.editTextEmail);
    addresse = (TextView) findViewById(R.id.editTextStreet);
    bynavn = (TextView) findViewById(R.id.editTextCity);
    final Button bdelete = (Button) findViewById(R.id.button2);//deletebutton
    final TextView tx1 = (TextView) findViewById(R.id.textView1);


    mydb = new DBAdapter(this);

    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        int Value = extras.getInt("id");

        if (Value > 0) {
            Cursor rs = mydb.getContact(Value);
            id_To_Update = Value;
            rs.moveToFirst();






            if (!rs.isClosed()) {
                rs.close();
            }


            navn.setText((CharSequence) nam);
            navn.setFocusable(false);
            navn.setClickable(false);

            addresse.setText((CharSequence) stre);
            addresse.setFocusable(false);
            addresse.setClickable(false);

            email.setText((CharSequence) ema);
            email.setFocusable(false);
            email.setClickable(false);

            navn.setEnabled(true);
            navn.setFocusableInTouchMode(true);
            navn.setClickable(true);

            email.setEnabled(true);
            email.setFocusableInTouchMode(true);
            email.setClickable(true);

            addresse.setEnabled(true);
            addresse.setFocusableInTouchMode(true);
            addresse.setClickable(true);


        }
    }

  }
  }

//and my displaycv.xml file

   <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".DisplayCv" >
<!--lav en button2 delete i din displayCV-->

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="370dp"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <TextView
        android:id="@+id/editTextName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="82dp"
        android:ems="10"
        android:text="@string/navn"
        android:inputType="text" >
    </TextView>


   </RelativeLayout>
  </ScrollView> 

Aucun commentaire:

Enregistrer un commentaire