I created a table view and display some text there with help of experts in android.
Now i wish to push a new view when user click on each cell of a table view.
I created a new class within the same package named Newview.java.
The labels are displaying correctly in three different rows.
But when i click the first cell the program is crashing.
Can you please help me where im going wrong.
HelloTableLayoutActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class HelloTableLayoutActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView name = (TextView)findViewById(R.id.label);
name.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent nameActivity =new Intent();
nameActivity .setClass(getApplicationContext(), Newview.class);
startActivity(nameActivity);
}
});
}
}
Main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TableRow>
<TextView
android:layout_column="1"
android:text="@string/name"
android:padding="3dip" />
<TextView
android:text="@string/initial"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="@string/hometown"
android:padding="3dip" />
<TextView
android:text="@string/state"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
Can anyone please help me how can i push a new view when click on the cell of table view in android.Thanks in advance.Hope for your help.
Declare your activity in the manifest like below:
To add your further activities to the manifest, add them in your
<application>tag as shown above with theNewview. So, that’s as far as your manifest goes. When it comes to code, there are a few things that you need to take care of.Firstly, whenever you want to display a new screen to the user, make it a point to convert the class into an Activity. You can do it as follows:
foorefers to an XML file name. Thisfoo.xmlwhich will be in yourres/layout/will contain another layout to display to your user. So, when you’re switching screens/activities, make sure you’ve yourfoo.xmlfilled with atleast aTextViewso that you don’t get confused as to whether your app is working or not.One last thing. When you
extendyour class withActivity, make sure youimportall related packages such asimport android.app.Activity;forActivityandimport android.os.Bundle;forpublic void onCreate(Bundle savedInstanceState). These are just examples.Hope this helps.