Android error that i can't understand. Can someone help me? - android

I have built a sql database and i have implement the searchview widget to ba able to use in android pre API 11
When i try to do a research, the application close itself and i get this error and other messages:
Error
08-19 15:15:25.560: E/dalvikvm(6838): Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11
08-19 15:15:25.560: I/dalvikvm(6838): Failed resolving Landroid/support/v7/widget/SearchView$5; interface 814 'Landroid/view/View$OnLayoutChangeListener;'
08-19 15:15:25.560: W/dalvikvm(6838): Link of class 'Landroid/support/v7/widget/SearchView$5;' failed
08-19 15:15:25.560: D/dalvikvm(6838): VFY: replacing opcode 0x22 at 0x0002
08-19 15:15:25.560: D/dalvikvm(6838): VFY: dead code 0x0004-000a in Landroid/support/v7/widget/SearchView;.addOnLayoutChangeListenerToDropDownAnchorSDK11 ()V
I don't know if is something wrong with my code or else.
There's someone can help me?
Thank you
i think the error is here
import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListView;
public class SearchableActivity extends ListActivity{
DatabaseTable db = new DatabaseTable(this);
final Context context=this;
ListView list;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
list=(ListView)findViewById(android.R.id.list);
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(getIntent());
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
Cursor c = db.getWordMatches(query, null);
c.moveToFirst();
}
}
}
I have tried to import android.support.v7.widget.Searchview, but it says that is never used, and the error doesn't disappear. for this project, i have created the MainActivity.Java, wich contain the SearchWidget, a DatabaseTable.java a definitions.txt wich contains the data, a Search.xml and a SearchActivity.Java (the code below), i have also put the meta tag in the MainActivity and in the SearchActivity, inside the Manifest, don't know if can bel Helpfull to insert here the code of every page...I really don't know what to do anymore !!
Sure, here's the code of my main activity
import android.os.Bundle;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.SearchView;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends ActionBarActivity implements OnClickListener{
ActionBar actionBar;
Button a;
Button b;
Button c;
Button d;
Button e;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getSupportActionBar();
actionBar.setTitle("Trial");
initialiseOnClick();
a.setOnClickListener(this);
b.setOnClickListener(this);
c.setOnClickListener(this);
d.setOnClickListener(this);
e.setOnClickListener(this);
}
//START SEARCHVIEWWIDGET
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
// Configure the search info and add any event listeners
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
onSearchRequested();
return true;
default:
return false;
}
}
// END SEARCHVIEWWIDGET
private void initialiseOnClick() {
// TODO Auto-generated method stub
a = (Button) findViewById (R.id.button_a);
b = (Button) findViewById (R.id.button_b);
c = (Button) findViewById (R.id.button_c);
d = (Button) findViewById (R.id.button_d);
e = (Button) findViewById (R.id.button_e);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.button_a:
Intent a = new Intent(MainActivity.this, EuropeActivity.class);
startActivity(a);
break;
case R.id.button_b:
Intent b = new Intent(MainActivity.this, AmericasActivity.class);
startActivity(b);
break;
case R.id.button_c:
Intent c = new Intent(MainActivity.this, AsiaActivity.class);
startActivity(c);
break;
case R.id.button_d:
Intent d = new Intent(MainActivity.this, OceaniaActivity.class);
startActivity(d);
break;
case R.id.button_e:
Intent e = new Intent(MainActivity.this, AfricaActivity.class);
startActivity(e);
break;
}
}
}

Related

Android:Not able to write on textview of main activity when comming from different activity

I created a simple demo program in which there is start button.When i click on start button on main (Home) screen "hi all" appended to Text view.It works fine, But when I change the activity from selecting action bar menu and if again come on the home screen by selecting the action bar home menu then it will not show the "hi all " Message when I click on the Start button.
package com.example.testdemo;
import android.app.ActionBar.LayoutParams;
import android.content.Intent;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.text.method.ScrollingMovementMethod;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView logArea;
private TextView log;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
ActionBar actionBar = getActionBar();
log = new TextView(MainActivity.this);
log.append("Heollosdfsjdf" + "\n");
#SuppressWarnings("deprecation")
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
params.gravity = Gravity.LEFT;
log.setLayoutParams(params);
log.setGravity(Gravity.CENTER);
LinearLayout chat = (LinearLayout) findViewById(R.id.main_linear_view);
log.setMovementMethod(new ScrollingMovementMethod());
chat.addView(log);
setDefault();
}
public void setDefault(){
Button btn = (Button) findViewById(R.id.start_recording_button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startWriting(v);
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
goHome();
return true;
case R.id.general_setting:
generalSetting();
return true;
case R.id.server_settings:
serverSetting();
return true;
case R.id.audio_settings:
audioSetting();
return true;
default:
break;
}
return true;
}
private void goHome() {
Intent i = new Intent(MainActivity.this, home.class);
startActivity(i);
finish();
}
private void generalSetting() {
Intent i = new Intent(MainActivity.this, general.class);
startActivity(i);
finish();
}
private void audioSetting() {
Intent i = new Intent(MainActivity.this, audio.class);
startActivity(i);
finish();
}
private void serverSetting() {
Intent i = new Intent(MainActivity.this, server.class);
startActivity(i);
finish();
}
public void startWriting(View view) {
logMessage("Hi all");
}
private void logMessage(String msg) {
log.append(msg + "\n");
final int scrollAmount = log.getLayout().getLineTop(log.getLineCount())- log.getHeight();
if (scrollAmount > 0)
log.scrollTo(0, scrollAmount);
else
log.scrollTo(0, 0);
}
}
it's because you called 'finish' when you changed activities. calling the main activity again reloads its view to its initial state.
In addition to MetaSnarf's answer: For a deeper understanding of the "Android Task Stack" and saving of the current Activity state, you might want to take a look at http://developer.android.com/guide/components/tasks-and-back-stack.html

Intent not passing correct information

Im using intents to pass the noteId from my database to a different activity for displaying the information it was working and i went to work on another part of the project and now it seems to only pass one value and from playing about i have found that seems to be whatever is the next highest object on the ListView. Sorry if this is badly worded, Im not very good at explaining these things
ViewNote Class
package com.hardy.passnotes;
import java.util.HashMap;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ViewNote extends Activity {
EditText NewNoteTitle;
EditText NewNoteContent;
TextView tvNoteId;
DBTools dbTools = new DBTools(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_note);
NewNoteTitle = (EditText)findViewById(R.id.ETNewNoteTitle);
NewNoteContent = (EditText)findViewById(R.id.ETNewNoteContent);
Intent n = getIntent();
String NoteId = n.getStringExtra("noteId");
Toast.makeText(getApplicationContext(), NoteId,
Toast.LENGTH_LONG).show();
HashMap<String, String> NoteList = dbTools.getNoteInfo(NoteId);
if(NoteList.size() != 0)
{
setTitle("Note: " + NoteList.get("noteTitle"));
NewNoteTitle.setText(NoteList.get("noteTitle"));
NewNoteContent.setText(NoteList.get("noteContent"));
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.view_note, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId())
{
case R.id.action_Editnote:
tvNoteId = (TextView)findViewById(R.id.NoteId);
String NoteValue = tvNoteId.getText().toString();
Intent intent = new Intent(getApplication(),EditNote.class);
intent.putExtra("noteId", NoteValue);
startActivity(intent);
case R.id.action_DelNote:
Intent intent1 = getIntent();
String NoteId = intent1.getStringExtra("noteId");
dbTools.deleteNote(NoteId);
Intent i = new Intent(getApplication(),MyNotes.class);
startActivity(i);
finish();
}
return super.onOptionsItemSelected(item);
}
}
MyNote Class:
package com.hardy.passnotes;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class MyNotes extends ListActivity {
DBTools dbTools = new DBTools(this);
TextView tvNoteId;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_notes);
Log.i("Tag", "OnCreate Started As Normal");
setTitle("My Notes");
ArrayList <HashMap<String, String>> NoteList = dbTools.getAllNotes();
if(NoteList.size() != 0)
{
ListView listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
tvNoteId = (TextView)findViewById(R.id.NoteId);
String NoteValue = tvNoteId.getText().toString();
Intent intent = new Intent(MyNotes.this,ViewNote.class);
intent.putExtra("noteId", NoteValue);
startActivity(intent);
Log.i("Tag", "if Started As Normal");
}
});
ListAdapter Adapter = new SimpleAdapter(MyNotes.this,NoteList,R.layout.notes_list, new String[]{"noteId","noteTitle",}, new int[]{R.id.NoteId,R.id.NoteTitle} );
setListAdapter(Adapter);
Log.i("Tag", "Arrey Started As Normal");
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_notes, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId())
{
case R.id.action_Add:
Intent i = new Intent(getApplicationContext(),CreateNote.class);
startActivity(i);
finish();
}
return super.onOptionsItemSelected(item);
}
}
Thanks in advance been searching around and debugging for hours with no luck.
Hi I think the problem is that you use the findViewById() method inappropriately in your onItemClick listener.
You should use:
tvNoteId = (TextView)view.findViewById(R.id.NoteId);
Notice that I call the findViewById method on the view given by the onItemClick method because you want to find the view with the id NoteId from the pressed item and not from the entire's activity content view.. the way you do it will search in the content view of your activity for the first id equal with NoteId ...
I think your note get deleted on the moment edit is clicked from the options menu.
At the end of case R.id.action_Editnote nothing is returned nor break is called so case R.id.action_Delnote will be executed as well. This is where you delete the note from your database.
In your switch, put a break:
switch (item.getItemId())
{
case R.id.action_Editnote:
tvNoteId = (TextView)findViewById(R.id.NoteId);
String NoteValue = tvNoteId.getText().toString();
Intent intent = new Intent(getApplication(),EditNote.class);
intent.putExtra("noteId", NoteValue);
startActivity(intent);
break;
case R.id.action_DelNote:
Intent intent1 = getIntent();
String NoteId = intent1.getStringExtra("noteId");
dbTools.deleteNote(NoteId);
Intent i = new Intent(getApplication(),MyNotes.class);
startActivity(i);
finish();
break;
}

having multiple choice game that will calculate the score of the user but the system crush out

i have a sample android application that will display flag of coutry and multiple choice using radio button and each time the user check one of the answers the system will check if true and add 25 points to its score using intent to pass from activity to another with transferring the data mean the score until the user play 4 times to get to the end where the system will display his score .
until now i did the MainActivity that pass the data to the second but the problem is that the system force to close and in the log cat this what its display:
can anyone help me to solve this problem ????
logcat
11-27 22:15:53.609: E/AndroidRuntime(4834): Caused by: java.lang.NullPointerException
11-27 22:15:53.609: E/AndroidRuntime(4834): at com.devleb.flagology.SecondActivity.onCreate(SecondActivity.java:56)
MainActivity.java
package com.devleb.flagology;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity {
Button btnS;
RadioGroup rdgS;
RadioButton rdS1, rdS2, rdS3, rdS4;
private int score =0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rdgS = (RadioGroup) findViewById(R.id.rdg1);
rdgS.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (rdS1.isChecked() || rdS2.isChecked() || rdS3.isChecked()
|| rdS4.isChecked()) {
btnS.setVisibility(View.VISIBLE);
}
}
});
rdS1 = (RadioButton) findViewById(R.id.rd_s1);
rdS2 = (RadioButton) findViewById(R.id.rd_s2);
rdS3 = (RadioButton) findViewById(R.id.rd_s3);
rdS4 = (RadioButton) findViewById(R.id.rd_s4);
btnS = (Button) findViewById(R.id.btn_s);
btnS.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this, SecondActivity.class);
switch (rdgS.getCheckedRadioButtonId()) {
case R.id.rd_s1:
i.putExtra("score", score);
break;
case R.id.rd_s2:
i.putExtra("score", score);
break;
case R.id.rd_s3:
i.putExtra("score", score + 25);
break;
case R.id.rd_s4:
i.putExtra("score", score);
break;
default:
break;
}
startActivity(i);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.hint_icon:
ShowAlertDialog();
break;
case R.id.about_icon:
Toast.makeText(this, "developed by Georges Matta",
Toast.LENGTH_SHORT).show();
default:
break;
}
return super.onOptionsItemSelected(item);
}
public void ShowAlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Hint")
.setMessage("The famouse sport is Bullfighting")
.setCancelable(false)
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
SecondActivity.java
package com.devleb.flagology;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class SecondActivity extends Activity {
Button btnI;
RadioGroup rdgI;
RadioButton rdI1, rdI2, rdI3, rdI4;
// TextView txt_result;
private int score = 0;
int finalScore = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Bundle extras = getIntent().getExtras();
if (extras != null) {
int value = extras.getInt("score");
finalScore = score + value;
rdgI = (RadioGroup) findViewById(R.id.rdg2);
rdgI.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (rdI1.isChecked() || rdI2.isChecked()
|| rdI3.isChecked() || rdI4.isChecked()) {
btnI.setVisibility(View.VISIBLE);
}
}
});
rdI1 = (RadioButton) findViewById(R.id.rd_I1);
rdI2 = (RadioButton) findViewById(R.id.rd_I2);
rdI3 = (RadioButton) findViewById(R.id.rd_I3);
rdI4 = (RadioButton) findViewById(R.id.rd_I4);
btnI = (Button) findViewById(R.id.btn_s);
btnI.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(SecondActivity.this,
ThirdActivity.class);
switch (rdgI.getCheckedRadioButtonId()) {
case R.id.rd_I1:
i.putExtra("score", finalScore);
break;
case R.id.rd_I2:
i.putExtra("score", finalScore);
break;
case R.id.rd_I3:
i.putExtra("score", finalScore);
break;
case R.id.rd_I4:
i.putExtra("score", finalScore);
break;
default:
break;
}
startActivity(i);
}
});
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
}
ThirdActivity.java
package com.devleb.flagology;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class ThirdActivity extends Activity {
TextView txt_result;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
txt_result = (TextView) findViewById(R.id.txtResult);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = String.valueOf(extras.getInt("score"));
txt_result.setText(value);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.third, menu);
return true;
}
}
I would venture to guess that your problem comes from this line:
btnS = (Button) findViewById(R.id.btn_s);
Most likely you made changes to your main activity layout (R.layout.activity_main) and either renamed or removed the <Button> element from it. If my guess is correct, then this line will fail to find the view in the inflated layout, and your btnS object will be null, leading to the actual exception you see.

SQLite android programming issue

MY program is note working on the emulator. There are no errors in the code from eclipse. It says that "the process has stopped unexpectedly". I have tried to run the xml code by it self and it comes up without a problem. I also have a db file of the same activity however I am more suspicious of this file being the cause of the problem. I cannot find any thing to help find the answer. I do not know much about programming but I have been researching this application. The solution to this would help many people who might have this problem or are interested in this activity.
I am interested in inserting a fixed text from a button into a database.
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Watchnotes extends Activity implements OnClickListener,
android.view.View.OnClickListener {
Button button1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_);
button1.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity, menu);
return true;
}
// public interface
public void onClick(View arg0) {
boolean didItWork = true;
try{
switch (arg0.getId()) {
case R.id.button1:
String note = "XXXX";
NAME entry = new NAMEdb(NAME.this);
entry.open();
entry.createEntry(note);
entry.close();}
}catch (Exception e){
didItWork = false;
}finally{
if (didItWork){
Dialog d = new Dialog(this);
d.setTitle("XXXX");
d.show();}
}
}
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
switch (((View) arg0).getId()){
case R.id.button5:
Intent i = new Intent("com.intent.LIST");
startActivity(i);}}}
we have the same problem. Just initialize
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main3);
addListenerOnButton1();
addListenerOnButton2();
}
public void addListenerOnButton1() {
final Context context = this;
button = (Button) findViewById(R.id.btn1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, App2Activity.class);
startActivity(intent);
}
});

using a generic class in android

Hi i am new to android..
i have the following code..
package squash.trainer;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class SquashTrainerActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Button btn_start = (Button) findViewById(R.id.btn_start);
//btn_start.setOnClickListener(new View.OnClickListener() {
// public void onClick(View v) {
// setContentView(R.layout.selecttopmenu);
// }});
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater. inflate(R.menu.mainmenu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item. getItemId() ) {
case R. id.btn1:
BugsSequence();
return true;
case R. id.btn2:
return true;
case R. id.btn3:
return true;
case R. id.btn4:
return true;
default:
return super. onOptionsItemSelected(item) ;
}
}
private void BugsSequence() {
// TODO Auto-generated method stub
}
}
for each case i want to use the a class to load the new layout and logic...
currently i have a test class called Bugssequence
package squash.trainer;
import android.os.Bundle;
import android.app.Activity;
//import android.view.View;
//import android.widget.Button;
public class BugsSequence extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
setContentView(R.layout.selecttopmenu);
}
/**
* #param args
*/
public static void main(String[] args) {
//
}
}
How can i get it load the new layout.. when i press on button 1.. it does nothing..
or is there a better way to load 4 different layouts /class(logic) one for each of the menus. Should i even be creating new activities for each screen / layout ?
Thanks you for your assistance...
Complete guide can be found here: http://developer.android.com/guide/topics/fundamentals/activities.html
At first, your activity should be declared in the manifest
<activity android:name=".YourActivity"
android:label="#string/youractivitylabel">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
and then you can start YourActivity from code:
Intent intent = new Intent(this, YourActivity.class);
startActivity(intent);
You can put easily some extra data into the intent and/or start it for a result
startActivityForResult(intent, PICK_CONTACT_REQUEST);
Read the link above, it's very useful!

Categories

Resources