1

I am planning to develop a word search game in android using grid view. I don't know how to select words in the grid view.

Allen
  • 681
  • 5
  • 16
  • 30

1 Answers1

1

This is a simple procedure with a filter data in grid view:

First,Open the main.xml file

Next,Add one edittext control and button control in xml file

for this add the following code

<EditText android:id="@+id/edtSearch"   
android:hint="Enter the item no" 
android:layout_width="200dip" 
android:layout_height="50dip"/> 

<Button android:id="@+id/SearchItem" 
android:text="Search Item" 
android:layout_width="180dip" 
android:layout_height="50dip" 
android:paddingLeft="10dip" /> 

Next,Save the file and create one class file and write the following code in the button event..

Button search = (Button) findViewById(R.id.SearchItem); 
search.setOnClickListener(new OnClickListener() { 
public void onClick(View v) { 
   performsearchoperation(); 
   Log.v("search button"," clicked"); 
   }    
}); 

Next,Write the following code performsearchoperation method

private void performsearchoperation() { 
// TODO Auto-generated method stub 
   Log.v("search button"," entered"); 
   EditText edittext=(EditText) findViewById(R.id.edtSearch); 
   ITEMID=edittext.getText().toString(); 
   int itemlength=ITEMID.length(); 
   Log.v("ILvalue ",String.valueOf(itemlength)); 
   Log.v("Ivalue ",String.valueOf(ITEMID.toString())); 
   if(itemlength==0) 
   { 
      Log.v("Item value ","zero"); 
      BindListView(); 
   } 
   else 
   { 
      Log.v("Item value ","Not zero"); 
      try{ 
         DBAdapter db = new DBAdapter(getBaseContext()); 
         db.open(); 
         Log.v("Entered","Item id"); 
         Cursor myCur = db.getItems_From_Search(ITEMID);    
         gridview.setAdapter(new MyAdapter(this,myCur)); 
         gridview.setVisibility(View.VISIBLE); 
         Log.v("parts count",String.valueOf(myCur.getCount())); 
         db.close(); 
      }catch (Exception e) { 
         Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_LONG).show(); 
         Log.v("Error",e.toString()); 
      } 
   } 
Log.v("data ",String.valueOf(ITEMID.toString())); 

}   
jlopez
  • 6,287
  • 2
  • 51
  • 90