how to make search function with edittext .
i have four edittext and one button.
while user fill details the data fatch to sqlit and display to activity 2 page.plz help me.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Laxmidhar SahooRank #383 · 6.6K reputationPosted May 23, 2020, 9:14 AM EDT
indradeo kumarRank #4,089 · 366 reputationPosted May 26, 2020, 7:28 PM EDT
Laxmidhar SahooRank #383 · 6.6K reputationPosted May 28, 2020, 11:48 PM EDT
indradeo kumarRank #4,089 · 366 reputationPosted Jun 9, 2020, 11:32 PM EDT
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(); } }xml version="1.0" encoding="utf-8"?> 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" /> AbsoluteLayout>Laxmidhar SahooRank #383 · 6.6K reputationPosted Jun 12, 2020, 8:29 AM EDT