i am using simple if else but not getting result [closed] - android

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have used two buttons and two edittexts in my code on clicking left button a new activity starts which is working properly. By clicking right it should show text entered in first edittext if it is present in array but it doesnt show anything in second edittext my code as follows
MainActivity.java
package com.example1.newactivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final int a;
Button b = (Button) findViewById(R.id.button1);
Button b1 = (Button) findViewById(R.id.button2);
final EditText e = (EditText) findViewById(R.id.editText1);
final EditText e1 = (EditText) findViewById(R.id.editText2);
final String values[] = new String[] { "Visual Basic", "C#", "C/C++",
"PHP", "Foxpro", "Delphi", "Java", "Perl",
"Ruby", "Cobol" };
a = values.length;
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Second.class));
}
});
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// startActivity(new Intent(MainActivity.this,Third.class));
String number = e.getText().toString();
number = number.toLowerCase();
for (int i=0 ; i<a ; i++){
if (number.equals(values[i].toLowerCase()))
{
e1.setText(values[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;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_marginLeft="46dp"
android:layout_toRightOf="#+id/button1"
android:text="Search"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="36dp"
android:layout_marginTop="82dp"
android:text="Contacts"
tools:ignore="HardcodedText" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button2"
android:layout_alignLeft="#+id/editText2"
android:layout_marginBottom="26dp"
android:layout_marginLeft="18dp"
android:ems="10"
android:inputType="textPersonName" />
</RelativeLayout>

You are typing in the wrong EditText (the one below both the buttons as that has request focus to it).
<EditText
android:id="#+id/**editText2"**
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:inputType="textPersonName" >
**<requestFocus />**
</EditText>
Type your text in the top most EditText and you shall see the effect. I rn and checked it myself. Have fun. :)

Related

How to put an x or cancel in AutoCompleteTextView Android [duplicate]

This question already has answers here:
how can I create clean Button in AutoCompleteTextView
(3 answers)
Closed 6 years ago.
This is the app that I am developing.
I am using AutoCompleteTextView.
I want to put an X inside it. Can you help me adding that?
Here is my code
MainActivity.class
package com.example.guidemo3;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;
public class MainActivity extends Activity {
AutoCompleteTextView autocomplete;
String[] stateName = { "France", "Philippines","Brazil",
"Italy", "United States"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autocomplete = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.simple_dropdown_item_1line, stateName);
autocomplete.setThreshold(1);
autocomplete.setAdapter(adapter);
autocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String stateName = autocomplete.getAdapter().getItem(position).toString();
// Put selected state to intent.
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("selectedState", stateName);
startActivity(intent);
}
});
TextView cancelButton = (TextView) findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
autocomplete.setText("");
}
});
}
}
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusableInTouchMode="true"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/search_view_border"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="20"
android:hint="Search"
android:padding="10dp">
<requestFocus/>
</AutoCompleteTextView>
<TextView
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" X "
android:textColor="#000"/>
</LinearLayout>
</RelativeLayout>
You have to put a LinearLayout around your AutoCompleteTextView
Then add your Background to that Layout
Place a TextView with an " X " as Text inside that Layout an add an OnClickListener.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/search_view_border"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:ems="20"
android:background="#android:color/transparent"
android:hint="Search"
android:padding="10dp">
<requestFocus/>
</AutoCompleteTextView>
<TextView
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" X "
android:textColor="#color/colorPrimaryDark"/>
</LinearLayout>
OnClickListener would look like this:
cancelButton = (TextView) findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
autocomplete.setText("");
}
});

how to display value of textbox on same screen in android application just like whatsaap

This is my main file where i am calling the click event on button to pass the value.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setTitle("aakash");
SetContentView(R.id.lst);
Button b = (Button) findViewById(R.id.sendbtn);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(android.view.View v) {
startActivity(new Intent(View.this,View.class));
}
});
}
**xml**
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
>
<TextView
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:textColor="#000000"
android:text="aakash"
android:background="#c0c0c0"
/>
<ScrollView
android:id="#+id/lst"
android:background="#fefefe"
android:layout_below="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_holder"
>
</ScrollView>
<EditText
android:id="#+id/chattxt"
android:layout_width="230dp"
android:layout_height="45dp"
android:hint="type here"
android:inputType="textMultiLine" />
<Button
android:id="#+id/sendbtn"
android:layout_width="75dp"
android:layout_height="45dp"
android:text="Send" />
</LinearLayout>
I want the value of textbox to display on the same screen(scrollview)box and also i want to pass a httppost request to pass a value..plz help me out
Thnks in advance
I think, you can use a ListView insted of scroll view. and add list items from the chat text value dynamically.
call notifydatasetchanged() every time when you add a new item to it.
<TextView
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:textColor="#000000"
android:text="aakash"
android:background="#c0c0c0"
/>
<ListView
android:id="#+id/listView_chats"
android:layout_width="match_parent"
android:layout_height="100dp"
>
</ListView>
<EditText
android:id="#+id/chattxt"
android:layout_width="230dp"
android:layout_height="45dp"
android:hint="type here"
android:inputType="textMultiLine" />
<Button
android:id="#+id/sendbtn"
android:layout_width="75dp"
android:layout_height="45dp"
android:text="Send" />
</LinearLayout>
Write a custom adapter for the listView and add the code to manage the list data.
i got the answer to my question
import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ButtonActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button);
}
public void setText(){
Button myButton = (Button)findViewById(R.id.button1);
final TextView myText = (TextView)findViewById(R.id.text1);
final EditText myInput = (EditText)findViewById(R.id.edit);
myButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
myText.setText(myInput.getText());
}
});
}
}

First simple Android app crashed by click on a button

my fist very simple android app is crashed, if I press my button. It's just a test. If the button click is working, I want to put an sql query in myClick function.
package com.example.connectdroid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#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;
}
void myClick(){
//here is my problem:
LinearLayout lView = (LinearLayout)findViewById(R.id.mylinear);
TextView selection = (TextView) findViewById(R.id.editText1);
String mytext = "apple";
selection.setText(mytext);
}
}
The xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:text="Button"
android:onClick="myClick" />
<LinearLayout
android:id="#+id/mylinear"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_below="#+id/button1"
android:layout_marginLeft="17dp"
android:layout_marginTop="57dp" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/mylinear"
android:layout_alignLeft="#+id/button1"
android:layout_marginBottom="22dp"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
</RelativeLayout>
void myClick(){
should be
public void myClick(View view){
Your app is crashing because you declared android:onClick="myClick" but the signature in the java file of myClick is wrong
thats true dear blackbelt,
The method called onClick should be following features
public method and
the method should contain View parameter

i found out that my R.java contains nothing, can someone tell me what to be written in R.java

error is that, R is underlined red! and com.example.guessthenumber.R is also underlined red!
when hovered it says to create a class R in package com.example.guessthenumber.R
xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/Guess"
android:gravity="start"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Done!" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:text="Enter your guessed number below"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#191970"
android:textStyle="bold" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_centerVertical="true"
android:text="0"
android:inputType="number" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_below="#+id/editText1"
android:layout_marginTop="29dp"
android:fontFamily="sans-serif-condensed"
android:text="#string/guess"
android:textColor="#000000"
android:textSize="22sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/game" />
</RelativeLayout>
below one is the java file:
package com.example.guessthenumber;
import android.os.Bundle;
import com.example.guessthenumber.R
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1 = (TextView) findViewById(R.id.textView1);
final TextView guessText = (TextView) findViewById(R.id.textView2);
final EditText userGuess = (EditText) findViewById(R.id.editText1);
Button b1 = (Button) findViewById(R.id.button1);
final String[] myNames={"Shashank","Sarthak","Gowda","$hankar"};
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String randText="";
// TODO Auto-generated method stub
int rando = (int) (Math.random()* 6);
int userNumber = Integer.parseInt(userGuess.getText().toString());
if(userNumber == rando){
guessText.setText("You got it right!");
}else{
guessText.setText("Guess again! :(");
}
randText=Integer.toString(rando);
t1.setText(randText);
userGuess.setText("0");
}
});
}
#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;
}
}
Replace:
import android.R;
by
import com.example.guessthenumber.R
OR
remove import.android.R and use ctrl+shift+O, organise imports if you are using eclipse.
Clean, build your project.
Also, pls read more about R:
Android: What is R? Why is it so Cryptic?
Check your imports - at the top of your activity, below your package name. And make sure it has something like this line:
import your_application_package_name.R;
Agreed with gunar's comment above,
In your xml, the "id" has not been defined properly, for your TextView. Please post the xml code, may be the activity's too.
Correct way for "id" in TextView, xml :
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Check that you are importing the R class from your package and not the Android's one. Check also that your resources do not contains error, otherwise the R class will not be generated.

How to switch between activities/screens in Android

my first Activity Xm
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#a5c63b"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:background="#434d23"
android:text="Ok To Continue"
android:onClick="frontt"
android:textColor="#a5c63b" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/question" />
<TextView
android:id="#+id/txtview11"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Loading..."
android:textSize="12dp" />
</RelativeLayout>
This is my Second Activity Xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#a5c63b"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="70dp"
android:onClick="onClick"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:background="#434d23"
android:text="OK"
android:textColor="#a5c63b" />
<EditText
android:id="#+id/txtedit"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignLeft="#+id/button1"
android:layout_alignParentTop="true"
android:layout_marginTop="50dp"
android:background="#edf2db"
android:ems="10"
android:inputType="numberDecimal" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/question" />
<TextView
android:id="#+id/txtview"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignBottom="#+id/txtedit"
android:layout_alignLeft="#+id/txtedit"
android:layout_marginBottom="21dp"
android:text="Guess Single Digit Number"
android:textSize="12dp" />
<TextView
android:id="#+id/txtview2"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignLeft="#+id/btn"
android:layout_below="#+id/btn"
android:text="TextView" />
</RelativeLayout>
this is my first java file code
package com.example.game;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.Button;
public class MainActivity extends Activity {
MediaPlayer btnsound;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.front);
Button next = (Button) findViewById(R.id.btn1);
btnsound = MediaPlayer.create(MainActivity.this,R.raw.game);
btnsound.start();
next.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent nextScreen = new Intent(getApplicationContext(), CopyOfMainActivity.class);
startActivity(nextScreen);
//finish();
}
} );
}
#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;
}
}
this is my Second java file
package com.example.game;
import java.util.Random;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.app.Activity;
import android.view.Menu;
public class CopyOfMainActivity extends Activity {
MediaPlayer btnsound;
Random random = new Random();
int randnumber = random.nextInt(10);
Button b2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnsound = MediaPlayer.create(CopyOfMainActivity.this,R.raw.game);
btnsound.start();
b2= (Button) findViewById(R.id.btn);
b2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
EditText input = (EditText)findViewById(R.id.txtedit);
TextView resultText = (TextView) findViewById(R.id.txtview2);
String inputstring = input.getText().toString();
int number = Integer.parseInt(inputstring);
if(randnumber==number)
{
resultText.setText("you win" );
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.win);
}
else if (number>randnumber)
{
resultText.setText("you guess high number" );
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.tryagain);
}
else if (number<randnumber)
{
resultText.setText("you guess low number" );
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageResource(R.drawable.lose);
}
}
} );
}
#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;
}
}
I have one button on First Activity xml layout .The first Activity Layout display after run application but whenever i click on button on first xml first want to go on next laytout after clicking then this error show in LogCat tab and application stop working.
AndroidRuntime at dalvik.system.NativeStart.main(Native Method)
what i should do?
The right way to do this given below:
next.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent nextScreen = new Intent(MainActivity.this, CopyOfMainActivity.class);
startActivity(nextScreen);
//finish();
}
} );
Hope this will work fine.
Please add your both activities to Manifest file if you missed out.
<application>
<activity android:name="Activity1">
</activity>
<activity android:name="Activity2">
</activity>
public void butt591(View v) {
v.startAnimation(fivenineclick);
Button but591 = (Button) findViewById(R.id.button591);
but591.setBackgroundColor(Color.parseColor("#ee4035"));
Intent bu591 = new Intent();
bu591.setClass(this, level5q10.class);
startActivity(bu591);
finish();
}
hey, i copy pasted a part of code in my app here 591 denotes level 5 ninth question and on selecting first option
that is wrong answer so on clicking the option it will set background to #ee4035 which is red color and when the user presses this option it will switch to level 5q10
I hope you understood from this code

Categories

Resources