2016-03-15 102 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