我创建了一个数据库应用程序,用户可以在其中搜索电影。然后,应用程序将在 ScrollView 中返回此搜索的结果。然后,我希望这些搜索结果是可点击的,这将导致另一个页面显示所选电影的完整详细信息。做这个的最好方式是什么?
public void search(View v){
EditText search = (EditText)findViewById(R.id.edtSearch);
String searchresult = "%" + search.getText().toString() + "%";
db = new DbHelper(this).getReadableDatabase();
String[] tblColumns = {"*"};
String where = "film LIKE ? OR actor LIKE ? OR actor2 LIKE ? OR director LIKE ?";
String[] args = {searchresult, searchresult, searchresult, searchresult};
Cursor results = db.query("FILMTABLE", tblColumns, where, args, null, null, null);
film(results);
}
public void film (Cursor c){
c.moveToFirst();
int titleIndex = c.getColumnIndex("film");
int idIndex = c.getColumnIndex("id");
String title = c.getString(titleIndex);
int filmID = c.getInt(idIndex);
TextView txt = new TextView(getApplicationContext());
txt.setId(filmID);
txt.setText(title);
txt.setTextColor(Color.BLACK);
txt.setTextSize(15);
ScrollView scrollView = (ScrollView)findViewById(R.id.scrolLView);
scrollView.addView(txt);
}
最佳答案
在数组列表中过滤搜索结果并使用 ListView 显示结果。然后实现listview.setOnItemClickListner。
按照此操作:http://www.javacodegeeks.com/2013/06/android-listview-tutorial-and-basic-example.html
关于java - 如何使搜索结果可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28859748/