我希望将AutocompleteTextView的值传递给Result值的字符串以进行查询以搜索列
这是我的主要活动
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);
}
});
}
}
这是我的结果:
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();
}
*/
}
我做了查询评论,以便我可以测试我的单词的值是否真的被传递。但它返回空白。