Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
while user fill details like id,name,mobile in edit text , if data match in sqlit table , then user profile like id, name mobile, email, address should be display on activity2. i have use android and java

Java
package com.example.indradeo;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.content.Intent;

public class MainActivity extends  Activity implements OnClickListener
    {
        EditText editRollno, editName, editMarks;
        Button  btnView;
        SQLiteDatabase db;
 /** Called when the activity is first created. */
 @Override
 public void onCreate (Bundle savedInstanceState)
        {
 super.onCreate( savedInstanceState );
            setContentView( R.layout.activity_main );
 editRollno = (EditText) findViewById( R.id.editRollno );
 editName = (EditText) findViewById( R.id.editName );
 editMarks = (EditText) findViewById( R.id.editMarks );

 btnView = (Button) findViewById( R.id.btnView );


 btnView.setOnClickListener( this );

 db = openOrCreateDatabase( "StudentDB", Context.MODE_PRIVATE, null );
 db.execSQL( "CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name VARCHAR,marks VARCHAR);" );
        }
 public void onClick (View view)
        {



 if (view == btnView) {
 if (editRollno.getText().toString().trim().length() == 0) {
                    showMessage( "Error", "Please enter Emp.ID" );
 return;
                }
                Cursor c = db.rawQuery( "SELECT * FROM student WHERE rollno='" + editRollno.getText() + "'", null );
 if (c.moveToFirst()) {
 editName.setText( c.getString( 1 ) );
 editMarks.setText( c.getString( 2 ) );
                } else {
                    showMessage( "Error", "Invalid Emp.ID" );
                    clearText();
                }
                String username = editRollno.getText().toString()+"\n";
                String location = editName.getText().toString();
                String designation = editMarks.getText().toString();

 //dbHandler.insertUserDetails(username,location,designation);
               // intent = new Intent(MainActivity.this,DetailsActivity.class);
                //startActivity(intent);
                //Toast.makeText(getApplicationContext(), "Details fatch Inserted Successfully",Toast.LENGTH_SHORT).show();
 }


        }
 public void showMessage (String title, String message)
        {
            Builder builder = new Builder( this );
            builder.setCancelable( true );
            builder.setCancelable( true );
            builder.setTitle( title );
            builder.setMessage( message );
            builder.show();
        }
 public void clearText ()
        {
 editRollno.setText( "" );
 editName.setText( "" );
 editMarks.setText( "" );
 editRollno.requestFocus();
        }
    }

<absolutelayout xmlns:android="http://schemas.android.com/apk/res/android" 
="" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/myLayout" android:stretchcolumns="0" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <textview
 android:layout_width="147dp" 
="" android:layout_height="33dp" android:layout_x="130dp" android:layout_y="206dp" android:text="@string/title">

    <textview
 android:layout_width="wrap_content" 
="" android:layout_height="wrap_content" android:layout_x="7dp" android:layout_y="310dp" android:text="@string/roll_no">

    <edittext
 android:id="@+id/editRollno" 
="" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="257dp" android:layout_y="297dp" android:inputtype="number">

    <textview
 android:layout_width="wrap_content" 
="" android:layout_height="wrap_content" android:layout_x="10dp" android:layout_y="370dp" android:text="@string/name">

    <edittext
 android:id="@+id/editName" 
="" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="254dp" android:layout_y="367dp" android:inputtype="text">

    <textview
 android:layout_width="wrap_content" 
="" android:layout_height="wrap_content" android:layout_x="2dp" android:layout_y="443dp" android:text="@string/marks">

    <edittext
 android:id="@+id/editMarks" 
="" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="254dp" android:layout_y="442dp" android:inputtype="number">

    <button
 android:id="@+id/btnView" 
="" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="287dp" android:layout_y="508dp" android:text="@string/Search">


What I have tried:

I have four edit text as employee details and one search button.
While user fill employee details in edit text and click on search button the employee details should be fetch database and display on activity two page ..using android java.
Posted
Updated 11-Jun-20 22:24pm
v4
Comments
Richard MacCutchan 12-Jun-20 3:53am    
Please edit your question, add the appropriate <pre> tags to your code, and explain exactly what your problem is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900