5 input based search form for Android
Disclaimer: I'm a C# developer and I haven't written Java in ages.

First of all I'd move this to a separate method, with (String selection, String[] selectionArgs) as parameters:

cursor = cupboard().withDatabase(sqLiteDatabase).query(Cattle.class)
        .withSelection(selection, selectionArgs)
        .getCursor();

if(cursor.getCount() &lt; 1){
    Toast.makeText(getContext(), "Sorry, No Cattle with those details!", Toast.LENGTH_LONG).show();


You can now call that method in each if instead of copy-pasting the same code over and over again and only changing a small part.



But I'm mostly baffled by the convoluted logic WRT those ifs and the resulting selection and selectionArgs. Are you sure you didn't mean to construct something like this (pseudo-code):

var selectionOptions = new Dictionary&lt;String, String&gt;();

if(breed != "" &amp;&amp; breed != "Breed")
{
   selectionOptions.Add("breed LIKE ?", breed);
}

if(sex != "" &amp;&amp; sex != "Sex")
{
   selectionOptions.Add("sex LIKE ?", sex);
}

// same for tag and name 

// now construct the selection
var selection = string.Join(" AND ", selectionOptions.Keys);

// pass the selection and its arguments to the method I mentioned above
ThatMethodMentionedAbove(selection, selectionOptions.Values);


The logic being:


Look at each of the four possible parameters
Only add a parameter to the query if it has a value and its value is not its own name


That would make sense to me, whereas this kind of logic:

if (tag == "" &amp;&amp; name == "" &amp;&amp; breed == "Breed"){
    // snip
    .withSelection("sex LIKE ?", sex)


... just looks... odd. And indeed, very un-maintainable.