ci-dessous, ne savent pas ce qui est le problèmeL'utilisation de deux ou plusieurs activty sur le code Android
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");
}
}
}
2ème classe
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<String> monthArray=new ArrayAdapter<String>(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);
}
}
fichier Manifest
enter code here<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="and.views"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".androidView"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AutoComplete" android:label="AutoComplete" android:launchMode="standard" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>