samedi 28 février 2015

Search is not bringing anything back

I have wrote code to bring back records from a 'DataHandler.java' file. However when I search anything nothing appears. The code is meant to get the film details from 'DataHandler.java' and display them in the ScrollView.



public void search (View v) {
EditText edtSearchTerm = (EditText) findViewById(R.id.edtSearch);
String searchTerm = "%" + edtSearchTerm.getText().toString() + "%";
db = new DataHandler(this).getReadableDatabase();
String[] tblColumns = {"*"};
String whereClause = "film LIKE ? OR actor1 LIKE ? OR actor2 LIKE ? OR director LIKE ?";
String[] whereArgs = {searchTerm, searchTerm, searchTerm, searchTerm};
Cursor searchResults = db.query("films", tblColumns, whereClause, whereArgs, null, null, null);
showFilms(searchResults);
}

public void showFilms(Cursor c) {
final LinearLayout resultLayout = (LinearLayout) findViewById(R.id.resultLayout);
if (resultLayout.getChildCount() > 0) {
resultLayout.removeAllViews();
}

while (c.moveToNext()) {
int titleIndex = c.getColumnIndex("title");
int directorIndex = c.getColumnIndex("director");
int idIndex = c.getColumnIndex("id");
String title = c.getString(titleIndex);
String director = c.getString(directorIndex);
int filmID = c.getInt(idIndex);

TextView txt = new TextView(getApplicationContext());
txt.setId(filmID);
txt.setText(title + ", " + director);
txt.setTextColor(Color.BLACK);
txt.setTextSize(15);
txt.setClickable(true);
txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity4.class);
intent.putExtra(FILM, String.valueOf(v.getId()));
startActivity(intent);
}
});
resultLayout.addView(txt);
}
};

Aucun commentaire:

Enregistrer un commentaire