2016-03-15 100 views
0

我正在Android工作室登录应用程序 当我打开应用程序我不能在用户名和密码字段(edittext-登录活动)输入任何东西..它不显示有一个EditText上! 我下面UI安卓工作室错误

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".Login" 
     android:label="@string/title_activity_login" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 


    <activity android:name=".SingUp"></activity> 

</application> 

我logcat的清单代码低于

03-15 07:42:08.206 2220-2220/com.example.dp_7_kholood.taskone I/art: Not late-enabling -Xcheck:jni (already on) 
03-15 07:42:08.253 2220-2220/com.example.dp_7_kholood.taskone W/System: ClassLoader referenced unknown path: /data/app/com.example.dp_7_kholood.taskone-1/lib/x86 
03-15 07:42:08.323 2220-2235/com.example.dp_7_kholood.taskone D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 
03-15 07:42:08.460 2220-2235/com.example.dp_7_kholood.taskone I/OpenGLRenderer: Initialized EGL, version 1.4 
03-15 07:42:08.491 2220-2235/com.example.dp_7_kholood.taskone W/EGL_emulation: eglSurfaceAttrib not implemented 
03-15 07:42:08.492 2220-2235/com.example.dp_7_kholood.taskone W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabfab2e0, error=EGL_SUCCESS 
03-15 07:42:11.887 2220-2235/com.example.dp_7_kholood.taskone W/EGL_emulation: eglSurfaceAttrib not implemented 
03-15 07:42:11.887 2220-2235/com.example.dp_7_kholood.taskone W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabfabdc0, error=EGL_SUCCESS 
03-15 07:42:11.967 2220-2235/com.example.dp_7_kholood.taskone W/EGL_emulation: eglSurfaceAttrib not implemented 
03-15 07:42:11.967 2220-2235/com.example.dp_7_kholood.taskone W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad809160, error=EGL_SUCCESS 
03-15 07:42:12.053 2220-2235/com.example.dp_7_kholood.taskone E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab850b20 
03-15 07:42:13.847 2220-2235/com.example.dp_7_kholood.taskone E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab850c70 
03-15 07:42:15.311 2220-2235/com.example.dp_7_kholood.taskone W/EGL_emulation: eglSurfaceAttrib not implemented 
03-15 07:42:15.311 2220-2235/com.example.dp_7_kholood.taskone W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabfab400, error=EGL_SUCCESS 
03-15 07:42:15.400 2220-2235/com.example.dp_7_kholood.taskone E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab8525d0 
a 

我登录活动XML

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Username" 
    android:id="@+id/TVusername" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/Tfusername" 
    android:layout_below="@+id/TVusername" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Password" 
    android:id="@+id/textView2" 
    android:layout_below="@+id/Tfusername" 
    android:layout_alignRight="@+id/TVusername" 
    android:layout_alignEnd="@+id/TVusername" 
    android:layout_marginTop="24dp" /> 

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:inputType="textPassword" 
    android:ems="10" 
    android:id="@+id/Tfpassword" 
    android:layout_below="@+id/textView2" 
    android:layout_alignLeft="@+id/textView2" 
    android:layout_alignStart="@+id/textView2" 
    android:layout_alignRight="@+id/Tfusername" 
    android:layout_alignEnd="@+id/Tfusername" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Login" 
    android:id="@+id/Blogin" 
    android:onClick="onButtonClick" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Sign Up" 
    android:id="@+id/BtnSingup" 
    android:layout_below="@+id/Blogin" 
    android:layout_alignLeft="@+id/Blogin" 
    android:layout_alignStart="@+id/Blogin" 
    android:onClick="onButtonClick" /> 

我的Java代码像下面

public class Login extends AppCompatActivity { 

DatabaseHelper helper=new DatabaseHelper(this); 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_login); 

} 

public void onButtonClick(View v){ 


    if (v.getId() == R.id.Blogin); 
    { 
     EditText a = (EditText)findViewById(R.id.Tfusername); 
     String str= a.getText().toString(); 
     EditText b = (EditText)findViewById(R.id.Tfpass); 
     String pass= b.getText().toString(); 
     String password= helper.searchPass(str); 

     if(pass.equals(password)){ 

     Intent i= new Intent(Login.this, SingUp.class); 
     i.putExtra("Username",str); 
     startActivity(i); 

    } 

     else{ 
      Toast t=Toast.makeText(Login.this, "Username and Paasword not match!", Toast.LENGTH_SHORT); 
      t.show(); 
     }} 
    if(v.getId()==R.id.BtnSingup){ 

     Intent i= new Intent(Login.this, SingUp.class); 
     startActivity(i); 
    } 
} 

}

+0

没有父视图?没有logcat? – Rainey

+0

我发布logcat结果 – Khulood

+0

为所有EditText视图提供背景颜色并查看它们是否正在显示。如果是的话,那么问题原因将是你的应用程序主题。检查主题。 –

回答

0

你的基础知识搞乱。

问题是你已经删除了父视图。只要做一件事:

创建一个新的活动。打开content_activity.xml(新的活动)做不要从这个XML文件中删除任何代码。您将获得默认的父视图。现在复制所有textviews和editTexts,并将其作为子视图添加到父视图中。像这样:

<RelativeLauout> 
    <TextView/> 
    <EditText/> 
</RelativeLayout> 

这里RelativeLayout是你的父视图。

这会帮助你理解这个概念。

+0

非常感谢.. – Khulood

+0

@Khulood当答案可以帮助你时,你总是可以'upvote'。这就像助手的cookie。 ;) –

0

改变布局的高度,试试这个:

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="30dp" 
    android:id="@+id/Tfusername" 
    android:layout_below="@+id/TVusername" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 
+0

还是不能写任何东西 – Khulood

+0

data/app/com.example.dp_7_kholood.taskone-2/lib/x86 03-15 09: 24:20.607 512-559/com.example.dp_7_kholood.taskone D/OpenGLRenderer:使用EGL_SWAP_BEHAVIOR_PRESERVED:true 03-15 09:24:20.665 512-559/com.example.dp_7_kholood.taskone I/OpenGLRenderer:初始化的EGL版本1.4 03-15 09:24:20.695 512-559/com.example.dp_7_kholood.taskone W/EGL_emulation:eglSurfaceAttrib未实施 03-15 09:24:20.695 512-559/com.example.dp_7_kholood.taskone W/OpenGLRenderer:无法在曲面0xabf3f4c0上设置EGL_SWAP_BEHAVIOR,错误= EGL_SUCCESS – Khulood

+0

您有没有像其他人所建议的那样用父视图包围所有视图? –

0

您没有父视图,你的代码直接与那就是你的TextView子视图开始。

这个小部件像textview,editext,buttons都应该有一个容器,即父视图,可以是相对布局或线性布局。

尝试的TextView之前添加以下代码:

<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"> 
</RelativeLayout> 
+0

想我想他是发布xml.its的主要部分不是问题.... –

+0

我尝试了您的代码,通过在textview之前添加此XML文件和你的editexts和所有的按钮是可见的,为我工作! –

+0

我觉得问题是在代码他是绑定edittext上登录按钮,所以它是如何工作的。 –

0

抱歉,但你已经捣碎整个代码,因此你无法看清显示屏上的用户界面。

下面的确切代码应该像下面这样代替你的xml文件,因为我没有改变你的参数,所以你可以替换它。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="10dp"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Username" 
    android:id="@+id/TVusername" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/Tfusername" 
    android:layout_below="@+id/TVusername" 
    android:layout_alignParentLeft="true"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="Password" 
    android:id="@+id/textView2" 
    android:layout_below="@+id/Tfusername" 
    android:layout_alignParentLeft="true" 
    android:layout_marginTop="24dp" /> 

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:inputType="textPassword" 
    android:ems="10" 
    android:id="@+id/Tfpassword" 
    android:layout_below="@+id/textView2" 
    android:layout_alignParentLeft="true"/> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Login" 
    android:id="@+id/Blogin" 
    android:onClick="onButtonClick" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Sign Up" 
    android:id="@+id/BtnSingup" 
    android:layout_below="@+id/Blogin" 
    android:layout_alignLeft="@+id/Blogin" 
    android:layout_alignStart="@+id/Blogin" 
    android:onClick="onButtonClick" /> 

+0

仍然无法编辑任何编辑文本 – Khulood