Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i click on button for open a new activity it show home page in emulator what can be the reason thanks in advance.. :)

//this code in mainactivity


Intent intent=new Intent(this,Result.class);
startActivity(intent);


>>>>>>>>>>>>>>>>activity code in manifest


HTML
<activity>
            android:name=".newcelci"
            android:label="@string/title_activity_newcelci" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" xmlns:android="#unknown" />

                <category android:name="android.intent.category.LAUNCHER" xmlns:android="#unknown" />
            </intent-filter>
        </activity>
        <activity>
            android:name=".Result"
            android:label="@string/title_activity_result" >
        </activity>


Java
package ahmadraza.com.firstapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class newcelci extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newcelci);
    }

    @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_newcelci, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    public void doadd(View v)
    {
        if(v.getId() == R.id.btnadd)
        {
            MessageBox("Hello World");
        }
    }

    public void MessageBox(String message)
    {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }
    // public void doadd(View view){
     //   EditText num1=(EditText)findViewById(R.id.etnum1);
       // EditText num2=(EditText)findViewById(R.id.etnum2);

        //int a=Integer.parseInt( num1.getText().toString());
        //int b=Integer.parseInt(num2.getText().toString());

        //Intent intent=new Intent(this,Result.class);
        //startActivity(intent);


        //TextView result=(TextView) findViewById(R.id.tvresult);
        //result.setText(String.valueOf(a+b));


    //}
public void dosub(View view){

    EditText num1=(EditText)findViewById(R.id.etnum1);
    EditText num2=(EditText)findViewById(R.id.etnum2);

    int a=Integer.parseInt( num1.getText().toString());
    int b=Integer.parseInt( num2.getText().toString());

    Intent intent1=new Intent(this,Result.class);
    startActivity(intent1);

    //TextView result=(TextView) findViewById(R.id.tvresult);
    //result.setText(String.valueOf(a-b));

   }
}


HTML
<!--?xml version="1.0" encoding="utf-8"?-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ahmadraza.com.firstapp">

    <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
        <activity android:name=".newcelci" android:label="@string/title_activity_newcelci">
            <intent-filter>
                <action android:name="android.intent.action.MAIN">

                <category android:name="android.intent.category.LAUNCHER">
            </category></action></intent-filter>
        </activity>
        <activity android:name=".Result" android:label="@string/title_activity_result">
        </activity>
    </application>

</manifest>



HTML
<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="ahmadraza.com.firstapp.newcelci">


    <textview android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/Number1"
              android:id="@+id/textView"
              android:layout_alignparenttop="true"
              android:layout_centerhorizontal="true">

    <edittext android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/etnum1"
              android:inputtype="number"
              android:layout_below="@+id/textView"
              android:layout_alignleft="@+id/etnum2"
              android:layout_alignstart="@+id/etnum2">

    <textview android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/Number2"
              android:id="@+id/textView2"
              android:layout_below="@+id/etnum1"
              android:layout_alignleft="@+id/textView"
              android:layout_alignstart="@+id/textView">

    <edittext android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/etnum2"
              android:inputtype="number"
              android:layout_below="@+id/textView2"
              android:layout_centerhorizontal="true">

    <textview android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/Result"
              android:id="@+id/textView3"
              android:layout_below="@+id/etnum2"
              android:layout_centerhorizontal="true">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/ADD"
        android:id="@+id/btnadd"
        android:/>


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/SUB"
        android:id="@+id/btnsub"
        android:/>

    <textview android:layout_width="wrap_content" 
              android:layout_height="wrap_content"
              android:id="@+id/tvresult"
              android:layout_below="@+id/btnsub"
              android:layout_centerhorizontal="true"
              android:layout_margintop="33dp">
    </textview>
    </textview>
    </edittext>
    </textview>
    </edittext>
    </textview>
</relativelayout>
Posted
Updated 15-Sep-15 9:01am
v2
Comments
Richard MacCutchan 15-Sep-15 7:51am    
Where is the Result class? Please edit your question and show a bit more of your code (properly formatted).
Member 11504333 15-Sep-15 14:28pm    
thats the code plz help its showing me msg when i click on add button but when i click on sub it doesnt show new activity....:( i just check as example to show msg on add button.....
Richard MacCutchan 15-Sep-15 15:04pm    
Well I have put the code in your question and formatted it as best I can, but it does not look right to me. I cannot see a Result class anywhere, and much of the XML is not correctly formatted. I suggest you go back to your application and take a closer look at what you are trying to do .
Member 11504333 16-Sep-15 3:59am    
Thanks Richard MacCutchan.....
i Have a question help me if U can.... plz
every time when i put any widgets in my activity and run on emulator their is a problem which show "hardcoded string" with a yellow mark...in my .XML file
i don't understand how i can solve this... plz give some idea thanks :)
Richard MacCutchan 16-Sep-15 4:13am    
Go to the Android documentation and learn how to write Android code the recommended way. You could also spend some time at http://www.codeproject.com/KB/android/#Android+Tutorial+Contest studying the Android articles.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900