2014-09-25 82 views
1

我有一個edittexts對他們的2個活動第一個活動工作正常,但第二個活動的EditText專注,但我不能編輯它,我也不能點擊它上面的按鈕。Android EditText不可編輯

此外,一切工作在模擬器,但不是當我安裝在設備上。 (鍵盤彈出還沒有出現在第二活性,其中,因爲它在所述第一活動一樣)

下面是the1st代碼和第二活動 第一個活動類

package com.rohan.rohan_pc.sportappnew; 

import android.content.Intent; 
import android.os.AsyncTask; 
import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 


public class LoginActivity extends ActionBarActivity { 

    EditText edtEmail, edtPassword; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_login); 

     //Initialize components 
     edtEmail = (EditText) findViewById(R.id.edtEmail); 
     edtPassword = (EditText) findViewById(R.id.edtPassword); 

     Button btnLogin = (Button) findViewById(R.id.btnLogin); 

     btnLogin.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       if (edtEmail.getText().toString().length() > 0 && edtPassword.getText().toString().length() > 0) { 
        new GetAllCustomerTask().execute(new ConnecterClass()); 
       } 
      } 
     }); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.login, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

    // Connect to the DB 
    private class GetAllCustomerTask extends AsyncTask<ConnecterClass, Long, JSONArray> 
    { 

     @Override 
     protected JSONArray doInBackground(ConnecterClass... params) { 
      // Execute in background 

      return params[0].usrLogin(edtEmail.getText().toString(), edtPassword.getText().toString()); 
     } 

     @Override 
     protected void onPostExecute(JSONArray jsonArray) { 

      if (jsonArray != null) { 
       JSONObject json = null; 
       try { 
        json = jsonArray.getJSONObject(0); 

        if (edtEmail.getText().toString().equals(json.getString("email"))) { 
         if (edtPassword.getText().toString().equals(json.getString("pass"))) { 
          Toast toast = Toast.makeText(getApplicationContext(), "login successful", Toast.LENGTH_SHORT); 
          toast.show(); 

          Intent intent = new Intent(LoginActivity.this, SearchActivity.class); 

          //Pass the school_id 
          intent.putExtra("SCHOOL_ID", json.getInt("school_id")); 

          startActivity(intent); 
         } else { 
          Toast toast = Toast.makeText(getApplicationContext(), "password incorrect", Toast.LENGTH_SHORT); 
          toast.show(); 
         } 
        } else { 
         Toast toast = Toast.makeText(getApplicationContext(), "failed to login ...", Toast.LENGTH_SHORT); 
         toast.show(); 
        } 
       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 

       //login(edtEmail.getText().toString(),"" 
/* 
       //Got to second screen if login is successful 
       Intent intent = new Intent(LoginActivity.this, AfterLogin.class); 

       //Pass the table name through 
       intent.putExtra("CLIENT_DB", clientDB); 

       startActivity(intent); 

       */ 
      } 
     } 
    } 
} 

第二活動課

> package com.rohan.rohan_pc.sportappnew; 

import android.content.Intent; 
import android.os.AsyncTask; 
import android.support.v7.app.ActionBarActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.WindowManager; 
import android.widget.AdapterView; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ListView; 
import android.widget.Toast; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 


public class SearchActivity extends ActionBarActivity { 

    EditText edtFName, edtLName, edtIDNum; 
    ListView listViewSearch; 

    String sFName, sLName, sIDNum; 

    int school_id; 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_search); 

     edtFName = (EditText) findViewById(R.id.edtFirstName); 
     edtLName = (EditText) findViewById(R.id.edtLastName); 
     edtIDNum = (EditText) findViewById(R.id.edtIDNum); 

     Button btnSearch = (Button) findViewById(R.id.btnSearch); 

     listViewSearch = (ListView) this.findViewById(R.id.listViewSearch); 

     //Initialize the default values for the search criteria variables 
     sFName = ""; 
     sLName = ""; 
     sIDNum = ""; 

     //Load school_id 
     school_id = getIntent().getExtras().getInt("SCHOOL_ID"); 

     if(edtFName.requestFocus()) { getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } 

     btnSearch.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 

       if(edtFName.getText().toString().length() > 0) 
       { 
        sFName = edtFName.getText().toString().trim(); 
       } 

       if(edtLName.getText().toString().length() > 0) 
       { 
        sLName = edtLName.getText().toString().trim(); 
       } 

       if(edtIDNum.getText().toString().length() > 0) 
       { 
        sIDNum = edtIDNum.getText().toString().trim(); 
       } 

       new SearchAllCustomers().execute(new ConnecterClass()); 

      } 
     }); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.search, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 



    //Search in the background 

    public void setListViewArray(final JSONArray jsonArray) 
    { 
     this.listViewSearch.setAdapter(new Search_ListView_Adapter(jsonArray, this)); 

     //Setup what happens when a user clicks on a searched item 
     this.listViewSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       try{ 
        JSONObject clickedItem = jsonArray.getJSONObject(position); 

        Intent askActivity = new Intent(getApplicationContext(), AskActivity.class); 
        askActivity.putExtra("IDNUM", clickedItem.getString("idnum")); 
        askActivity.putExtra("SCHOOL_ID", clickedItem.getInt("school_id")); 

        startActivity(askActivity); 

       } catch (JSONException e) { 
        e.printStackTrace(); 
       } 
      } 
     }); 
    } 

    // Connect to the DB 
    private class SearchAllCustomers extends AsyncTask<ConnecterClass, Long, JSONArray> 
    { 

     @Override 
     protected JSONArray doInBackground(ConnecterClass... params) { 
      // Execute in background 

      return params[0].searchPlayers(school_id, sFName, sLName, sIDNum); 
     } 

     @Override 
     protected void onPostExecute(JSONArray jsonArray) { 

      if (jsonArray != null) { 

       setListViewArray(jsonArray); 

       //login(edtEmail.getText().toString(),"" 
/* 
       //Got to second screen if login is successful 
       Intent intent = new Intent(LoginActivity.this, AfterLogin.class); 

       //Pass the table name through 
       intent.putExtra("CLIENT_DB", clientDB); 

       startActivity(intent); 

       */ 
      } 
     } 
    } 
} 

的XML - 第一個活動

<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=".LoginAcivity"> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="textEmailAddress" 
     android:ems="10" 
     android:id="@+id/edtEmail" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="52dp" 
     android:hint="email ..." 
     /> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="textPassword" 
     android:ems="10" 
     android:id="@+id/edtPassword" 
     android:layout_below="@+id/edtEmail" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="44dp" 
     android:hint="password ..." 
     /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/btnLogin" 
     android:layout_below="@+id/edtPassword" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="49dp" /> 
</RelativeLayout> 

的XML - 第二個活動

<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="com.rohan.rohan_pc.sportsappv001.SearchActivity"> 

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

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="textPersonName" 
    android:hint="Name" 
    android:ems="10" 
    android:id="@+id/edtFirstName" 
    android:layout_below="@+id/textView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="textPersonName" 
    android:hint="Surname" 
    android:ems="10" 
    android:id="@+id/edtLastName" 
    android:layout_below="@+id/edtFirstName" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/edtIDNum" 
    android:hint="ID Number" 
    android:layout_below="@+id/edtLastName" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignRight="@+id/edtLastName" 
    android:layout_alignEnd="@+id/edtLastName" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Search" 
    android:id="@+id/btnSearch" 
    android:layout_below="@+id/edtIDNum" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginLeft="64dp" 
    android:layout_marginTop="42dp" /> 

<ListView 
    android:layout_width="wrap_content" 
    android:layout_height="200dp" 
    android:id="@+id/listViewSearch" 
    android:layout_alignParentBottom="true" 
    android:layout_toEndOf="@+id/edtIDNum" 
    android:layout_alignTop="@+id/edtFirstName" 
    android:clickable="true" 
    /> 

+0

你的第二個活動在哪裏? – santalu 2014-09-25 18:46:27

+0

這是我沒有發佈它的第二個活動,因爲它正在工作,因此我只想到問題似乎是我發佈的地方 – user3772063 2014-09-25 18:49:06

+0

嘗試if(myEditText.requestFocus()){getWindow()。setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE ); } – extmkv 2014-09-25 18:55:34

回答

0

我只是想出重新創建的應用程序。我不認爲這是一個明智的決定,將原始文件複製到另一個目錄並使用它。