package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
public class Test extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater(); //from activity
inflater.inflate(R.menu.my_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
appendMenuItemText(item);
if (item.getItemId() == R.id.menu_clear)
{
this.emptyText();
return true;
}
return true;
}
private TextView getTextView()
{
return (TextView)this.findViewById(R.id.text1);
}
public void appendText(String abc)
{
TextView tv = getTextView();
tv.setText(tv.getText() + "\n" + abc);
}
private void appendMenuItemText(MenuItem menuItem)
{
String title = menuItem.getTitle().toString();
TextView tv = getTextView();
tv.setText(tv.getText() + "\n" + title);
}
private void emptyText()
{
TextView tv = getTextView();
tv.setText("");
}
}
//main.xml
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your debug will appear here"
/>
//my_menu.xml