Reputation: 1239
hi ppl (im noob with android) I create one aplication but the app cant open one new activity to open more layouts, can help me?
my code is:
Layout main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f9f9f9"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<Button
style="@style/Button"
android:text="@string/wireless"
android:onClick="OpenWireless"
/>
<Button
style="@style/Button"
android:text="Button 1"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
wireless.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f9f9f9"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<Button
style="@style/Button"
android:text="On/Off"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Activity: MainActivity:
package pacl.hackdroid;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity
{
/** Called when the activity is first created.
* @param savedInstanceState */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void OpenWireless(View view)
{
TextView textView;
textView = (TextView) findViewById(R.id.textView);
textView.setText("123");
Intent Wireless;
Wireless = new Intent(this, WirelessActivity.class);
}
}
WirelessActivity:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pacl.hackdroid;
import android.app.Activity;
import android.os.Bundle;
/**
*
* @author simao.lemos
*/
public class WirelessActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.wireless);
// ToDo add your GUI initialization code here
}
}
What is my bug?
Upvotes: 0
Views: 79
Reputation: 2129
Add startActivity here
Intent wirelessIntent = new Intent(this, WirelessActivity.class);
startActivity(wirelessIntent);
And also mention activity in manifest file in between application tags, like this
<activity android:name=".WirelessActivity"
/>
Otherwise app will show you force close after clicking on the button.
Upvotes: 1
Reputation: 1973
Change your this method
public void OpenWireless(View view)
{
TextView textView;
textView = (TextView) findViewById(R.id.textView);
textView.setText("123");
Intent Wireless;
Wireless = new Intent(this, WirelessActivity.class);
startActivity(Wireless);
}
this will open next activity.
Upvotes: 0
Reputation: 2088
An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.
public class MainActivity extends Activity
{
/** Called when the activity is first created.
* @param savedInstanceState */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
OpenWireless();
}
public void OpenWireless()
{
TextView textView;
textView = (TextView) findViewById(R.id.textView);
textView.setText("123");
Intent w;
w = new Intent(this, WirelessActivity.class);
startActivity(w);
}
}
Upvotes: 0
Reputation: 10948
You forgot to call startActivity
:
Intent Wireless;
Wireless = new Intent(this, WirelessActivity.class);
startActivity(Wireless);
Upvotes: 1