package and.views;
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;
public class androidView extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0,0, 0, "AutoComplete"); menu.add(0,1, 1, "Button"); menu.add(0,2, 2, "CheckBox"); menu.add(0,3, 3, "EditText"); menu.add(0,4, 4, "RadioGroup"); menu.add(0,5, 5, "Spinner");
return true;
}
/** Override onOptionsItemSelected to execute code for each menu item */
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case 0:
showAutoComplete();
return true;
case 1:
return true;
case 2:
return true;
case 3:
return true;
case 4:
return true;
case 5:
return true;
}
return true;
}
public void showAutoComplete()
{
Intent autocomplete = new Intent(this, AutoComplete.class);
try{
this.startActivity(autocomplete);
} catch(Exception e) { System.out.print(" activity not found"); } } }
2nd class
package and.views;
import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button;
public class AutoComplete extends Activity{ public void onCreate(Bundle icircle) { super.onCreate(icircle); setContentView(R.layout.autocomplete); ArrayAdapter monthArray=new ArrayAdapter(this, android.R.layout.simple_list_item_1, Months); final AutoCompleteTextView textView= (AutoCompleteTextView)findViewById(R.id.testAutoComplete); textView.setAdapter(monthArray); final Button changeButton=(Button)findViewById(R.id.testAutoComplete); changeButton.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { changeOption(textView); }
});
final Button changeButton2 = (Button) findViewById(R.id.textColorButton);
changeButton2.setOnClickListener(new Button.OnClickListener()
{ public void onClick(View v)
{ changeOption2(textView);
}
});
}
static final String[]Months= new String[]{ "January","February","March","April","May","June","July","August", "September","October","November","December" };
public void changeOption(AutoCompleteTextView text)
{
if (text.getHeight()==100){ text.setHeight(30);
}
else
{
text.setHeight(100);
}
} public void changeOption2(AutoCompleteTextView text)
{
text.setTextColor(Color.RED);
}
}
Manifest file
enter code here<?xml version="1.0" encoding="utf-8"?>
<activity android:name=".AutoComplete" android:label="AutoComplete" android:launchMode="standard" android:enabled="true">