2012-08-05 64 views
0

我正在学习android,因此我编写了以下代码以学习ScrollView并在linearlayout内部创建多个linearlayouts。我创建了一个菜单来启动不同的活动,但问题是当我单击与此xml文件关联的类时,新类(活动)未显示在屏幕上。可能是什么问题,我该如何解决?这里是代码:Android XML文件阻止活动打开

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="100" 
android:padding="25dp" > 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="30" 
> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
> 
<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Name" /> 

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" > 

    <requestFocus /> 
</EditText> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Age" /> 

<EditText 
    android:id="@+id/editText2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Email Address" /> 

<EditText 
    android:id="@+id/editText3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" /> 

<TextView 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Subject" /> 

<EditText 
    android:id="@+id/editText4" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" /> 

<TextView 
    android:id="@+id/textView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Phone No." /> 

<EditText 
    android:id="@+id/editText5" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" /> 

<TextView 
    android:id="@+id/textView6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Your Message" /> 

<EditText 
    android:id="@+id/editText6" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" /> 
</LinearLayout> 
</ScrollView> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:layout_weight="40"> 
<Button 
    android:id="@+id/button1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingTop="20dp" 
    android:text="Email" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="30" 
    android:orientation="vertical"> 
<AnalogClock 
    android:id="@+id/analogClock1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 
</LinearLayout> 

类电子邮件代码:

package com.umer.practice2; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.AnalogClock; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class Email extends Activity { 

TextView t1,t2,t3,t4,t5,t6; 
EditText e1,e2,e3,e4,e5,e6; 
Button butn; 
AnalogClock clock; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.email); 
    initializeviews(); 
} 

private void initializeviews() { 
    // TODO Auto-generated method stub 
    t1= (TextView) findViewById(R.id.textView1); 
    t2= (TextView) findViewById(R.id.textView2); 
    t3= (TextView) findViewById(R.id.textView3); 
    t4= (TextView) findViewById(R.id.textView4); 
    t5= (TextView) findViewById(R.id.textView5); 
    t6= (TextView) findViewById(R.id.textView6); 
    e1= (EditText) findViewById(R.id.editText1); 
    e2= (EditText) findViewById(R.id.editText2); 
    e3= (EditText) findViewById(R.id.editText3); 
    e4= (EditText) findViewById(R.id.editText4); 
    e5= (EditText) findViewById(R.id.editText5); 
    e6= (EditText) findViewById(R.id.editText6); 
    butn=(Button) findViewById(R.id.button1); 
    clock= (AnalogClock) findViewById(R.id.analogClock1); 
} 


} 
+0

你说的显示不出来是什么意思?你得到一个forceclose?如果是这样,发布LogCat。 – 2012-08-05 13:31:54

+0

您是否将电子邮件活动添加到清单中?你的开始活动代码是什么? – Olsavage 2012-08-05 13:35:41

回答

0

你有没有添加在AndroidManifest.xml的活动?每个活动都需要添加到清单文件中。

例如:

<activity android:name=".HelloGoogleMaps" android:label="@string/app_name"/> 
+0

冬青f ** k。我忘了那个。我的错。 – 2012-08-05 16:23:16

+0

很高兴我能帮到你。 – 2012-08-06 05:14:13