Can't control cursor position in edittext - android

I am practising android development, and I'm trying to follow guides on how to make a Twitter client app. I'm implementing my compose activity, but when I run the app the cursor is shown far down from the first line. I've followed many tips on stackoverflow to fix it but couldn't
here's a screenshot: http://t.co/qNA0gssOUG
ComposeActivity.java
package codepath.exercises.tweets;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
public class ComposeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose);
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Button tweetButton = (Button) findViewById(R.id.tweet_button);
Button cancelButton = (Button) findViewById(R.id.cancel_button);
final EditText tweetEditText = (EditText) findViewById(R.id.edittext_tweet);
tweetEditText.requestFocus();
tweetEditText.setSelection(0);
tweetButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
imm.hideSoftInputFromWindow(tweetEditText.getWindowToken(), 0);
}
});
cancelButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
imm.hideSoftInputFromWindow(tweetEditText.getWindowToken(), 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.compose, menu);
return true;
}
}
activity_compose.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="#efefef"
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=".ComposeActivity" >
<Button
android:id="#+id/cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/edittext_tweet"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:text="#string/cancel_button" />
<EditText
android:id="#id/edittext_tweet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="#id/cancel_button"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:inputType="textMultiLine" />
<Button
android:id="#+id/tweet_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/cancel_button"
android:layout_alignBottom="#+id/cancel_button"
android:layout_alignRight="#id/edittext_tweet"
android:text="#string/tweet_button" />
</RelativeLayout>

If I understand correctly, what you are seeing is the normal behavior of the EditText. The cursor appears at the center line.

set gravity top for edittext
<EditText
android:id="#id/edittext_tweet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="#id/cancel_button"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:gravity="top"
android:inputType="textMultiLine" />

You can add
android:gravity="top"
to EditText in Xml

Related

Add checkboxes on click

I have an image file on which if clicked anywhere I would like X'd checkboxes to show up. (Right now its set up as check marks). The code that I have is just for connecting page 1 to page 2 with a button click. Here it is
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
public static Button button1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnclickButtonListener();
}
public void OnclickButtonListener() {
button1 = (Button) findViewById(R.id.nextpage);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText userTextEntry = (EditText)findViewById(R.id.BRinfo);
String userdata = userTextEntry.getText().toString();
int userNumber = Integer.parseInt(userdata);
Intent intent = new Intent(MainActivity.this,Page2.class);
intent.putExtra("para name",userNumber);
startActivity(intent);
}
});
}}
Part of the XML code is
<?xml version="1.0" encoding="utf-8"?>
<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="vt.tacticalcombat.MainActivity"
android:clickable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:src="#mipmap/combat2"
android:layout_alignBottom="#+id/editText17"
android:layout_alignLeft="#+id/last4"
android:layout_alignStart="#+id/last4"
android:layout_alignRight="#+id/tableLayout"
android:layout_alignEnd="#+id/tableLayout"
android:layout_alignTop="#+id/imageView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEXT"
android:id="#+id/nextpage"
android:layout_alignBottom="#+id/tableLayout"
android:layout_alignRight="#+id/otherinfo"
android:layout_alignEnd="#+id/otherinfo"
tools:ignore="HardcodedText,RtlHardcoded"
android:nestedScrollingEnabled="true" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox28"
android:checked="false"
android:visibility="visible"
android:layout_alignBottom="#+id/rarmtypeinfo"
android:layout_toRightOf="#+id/mvc"
android:clickable="true"
android:layout_toEndOf="#+id/mvc" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_alignBottom="#+id/checkBox28"
android:layout_alignRight="#+id/injury"
android:layout_alignEnd="#+id/injury"
android:layout_alignTop="#+id/larmtype"
android:layout_alignLeft="#+id/checkBox28"
android:layout_alignStart="#+id/checkBox28" />
</RelativeLayout>
I tried using this link! but it did not work. How can I do this? Any help is appreciated

Custom_toast and custom_toast_layout_id not resolved [duplicate]

This question already has answers here:
Custom toast on Android: a simple example
(18 answers)
Closed 7 years ago.
I am trying to run a toast app. where one button shows a normal toast message and the second button shows a custom toast with an image (ic_launcher) and some text.
The normal toast works fine without the second button code inserted. For the custom toast.
1.custom_layout and 2. custom_toast_layout_id are not recognized and the application shows an error.
Here is the xml layout:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/ivImage"
android:layout_marginRight="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Press"
android:id="#+id/button"
android:layout_below="#+id/tv1"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Press Again"
android:id="#+id/button2"
android:layout_marginTop="56dp"
android:layout_below="#+id/button2"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/tvToast"
android:textColor="#000"/>
</RelativeLayout>
This is my activity:
package com.example.rahulshukla.myapplication;
import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class MainActivity extends Activity {
TextView helloText;
Button press, press2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
press.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"This is a Toast", Toast.LENGTH_LONG).show();
}
});
press2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast, (ViewGroup) findViewById(R.id.custom_toast_layout_id));
ImageView image = (ImageView)findViewById(R.id.ivImage);
image.setImageResource(R.drawable.ic_launcher);
TextView toastText = (TextView)findViewById(R.id.tvToast);
toastText.setText("Button is clicked");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL,0,0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
});
}
private void initialize() {
helloText = (TextView)findViewById(R.id.tv1);
press = (Button)findViewById(R.id.button);
press2 = (Button)findViewById(R.id.button2);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
Add id here . set id android:id="#+id/custom_toast_layout_id" & set this layout name custom_toast.xml.Then clean -Rebuild-Restart
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="#+id/custom_toast_layout_id">

How to add a ShowcaseView that pops up only for the first time to show how to use our app?

I wanted to do some thing like this as shown in image below,Is there any widget to do this or we need to add a view & make it transparent.
Thanks .
you must be create a custom view for it and make it transparent..
Main Activity:
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.Dialog;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initPopup();
}
#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;
}
public void initPopup() {
final Dialog view = new Dialog(this);
view.requestWindowFeature(Window.FEATURE_NO_TITLE);
view.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
view.setContentView(R.layout.transparent_layout);
view.setCanceledOnTouchOutside(true);
view.show();
RelativeLayout rl_chooseone_menu_main = (RelativeLayout) view
.findViewById(R.id.rl_chooseone_menu_main);
rl_chooseone_menu_main.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
view.dismiss();
}
});
/*Handler handler = null;
handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
view.cancel();
view.dismiss();
}
}, 3000);*/
}
}
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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
This is the Transparent View name is transparent_layout.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:background="#android:color/transparent" >
<RelativeLayout
android:id="#+id/rl_chooseone_menu_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageView1"
android:layout_marginRight="30dp"
android:text="Tap to view all" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="26dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageView2"
android:layout_alignRight="#+id/imageView2"
android:text="Tap to place your order" />
</RelativeLayout>
</RelativeLayout>
Enjoy Brother,i have used dimmy images,replace it with your own images..
You could make a tutorial Activity with a semi-transparent background, containing ImageViews and/or TextViews as shown in your example.
Tutorial activity's layout
<LinearLayout ...
android:background="#color/semitransparent"
... >
...
colors.xml
...
<color name="semitransparent">#80000000</color>
...
Then just start it on top of your usual Activity if you notice this is the first launch of your app by the user.

Android app not able to open web link

I have a button at the end of this app that takes the user to their default browser and to a predetermined link. Unfortunately, that button is broken. I am unsure of whether this is a problem with Java or with XML, but the code for both is attached.
package com.example.ldsm3;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity
import android.content.DialogInterface;
import android.content.Intent;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;
public class Finished extends Activity {
public void onClick(Button button1)
{
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("URL HERE"));
startActivity(browserIntent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_finished);
// tv is the ID for the TextView in the XML file
TextView tv = (TextView) findViewById(R.id.textView2);
// set the TextView to show the score
tv.setText(Misc.correct + "/" + Misc.total);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.finished, menu);
return true;
}
}
And the XML code...
<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=".Finished" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="69dp"
android:text="#string/Finished" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/textView1"
android:layout_marginBottom="19dp"
android:text="Go to the game!" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="93dp"
android:text="0/0" />
</RelativeLayout>
How do I fix this? Is it because of XML or Java? Did I not properly define the intent?
You need to add this on your onCreate() method:
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
//Do your stuff here
}
});

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