samedi 7 mai 2016

Passing Data With Intent to Search Data Database SQLite

i passing data keyword search with intent for get result in other activity. the keyword search use to search data from database sqlite, but i can't display the result with textView, there is no error in logcat. what problem with my code? there is my code to display output

OutputSuccess.java

package com.mjusuf.halal;

import android.support.v7.app.ActionBarActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class OutputSuccess extends ActionBarActivity {
    // Objects And Variables
    private String select;
    // User Information Variables
    String c2, c3, c4, c5, c6;

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

        TextView certificate_no = (TextView) findViewById(R.id.textView3);
        TextView valid_from = (TextView) findViewById(R.id.textView6);
        TextView valid_to = (TextView) findViewById(R.id.textView9);
        TextView company = (TextView) findViewById(R.id.textView12);
        TextView product_name = (TextView) findViewById(R.id.textView15);
        // name.setText(getIntent().getExtras().getString("search"));

        DatabaseHandler db = new DatabaseHandler(this);
        SQLiteDatabase db1 = db.getReadableDatabase();
        select = "SELECT * FROM certificate WHERE Certificate_No='"
                + getIntent().getExtras().getString("search") + "'";
        Cursor c1 = db1.rawQuery(select, null);
        if (c1 != null && c1.moveToFirst())
            do {
                certificate_no.setText(c1.getString(c1.getColumnIndex("Certificate_No")));
                valid_from.setText(c1.getString(c1.getColumnIndex("Valid_From")));
                valid_to.setText(c1.getString(c1.getColumnIndex("Valid_To")));
                company.setText(c1.getString(c1.getColumnIndex("Company")));
                product_name.setText(c1.getString(c1.getColumnIndex("Product_Name")));
            } while (c1.moveToNext());
    };

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.output_success, 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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Aucun commentaire:

Enregistrer un commentaire