I wanted my AutocompleteTextView's value to be passed to the string at the Result value to make a query to search a column
Here's my main activity
Button Btn_AddToDB,Btn_Search;
AutoCompleteTextView actv;
ArrayAdapter<String> myAdapter;
DBhandler dBhandler;
Cursor mItemCursor;
SQLiteDatabase db;
TextView Diesease, Definition, Medicine;
String word;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dBhandler = new DBhandler(MainActivity.this);
actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
ArrayAdapter<String> ard = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, str);
actv.setAdapter(ard);
actv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?>arg0, View arg1, int arg2, long arg3) {
word = String.valueOf(arg0.getItemAtPosition(arg2));
}
});
Btn_AddToDB = (Button) findViewById(R.id.AddToDBbutton);
Btn_Search = (Button) findViewById(R.id.SearchButton);
String word = actv.getText().toString();
Btn_AddToDB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent myintent = new Intent(MainActivity.this, AddDB.class);
MainActivity.this.startActivity(myintent);
}
});
Btn_Search.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent myintent = new Intent(MainActivity.this, Result.class);
MainActivity.this.startActivity(myintent);
}
});
}
}
and here's my result :
SQLiteDatabase db; TextView Diesease, Definition, Medicine;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
// try {
LayoutInflater auto = getLayoutInflater();
View textsss = auto.inflate(R.layout.activity_main, null);
Diesease = (TextView)findViewById(R.id.Diesease_Textview);
Definition= (TextView)findViewById(R.id.Definition_Textview);
AutoCompleteTextView textView = (AutoCompleteTextView)textsss.findViewById(R.id.autoCompleteTextView);
String words = textView.getText().toString();
Diesease.setText(words);
/*
Cursor res = db.rawQuery("SELECT DEFINITION FROM " + Dictionary.Medictionary.Tablename + " WHERE " +Dictionary.Medictionary.Diesease+ " ='" +word+"'", null);
if (res.moveToFirst())
{
Diesease.setText(words);
String define = res.getString(res.getColumnIndex("DEFINITION"));
Definition.setText(define);
}
else
{
Toast.makeText(getApplicationContext(), "DATA NOT AVAILABLE", Toast.LENGTH_LONG).show();
}
res.close();
}
catch (Exception ex)
{
Toast.makeText(getApplicationContext(),ex.getMessage(),Toast.LENGTH_LONG).show();
}
*/
}
I made the query comment so that I CAN TEST the value of my word is really being passed.But it returns blank.