Android EditText无法编辑

时间:2014-09-25 18:43:09

标签: android

我有2个关于edittexts的活动,第一个活动正常工作,但第二个活动的EditText聚焦但我无法编辑它,也无法点击它上面的按钮。

此外,一切都在模拟器中工作,但在我在设备上安装时却不行。 (键盘弹出窗口也没有出现在第二个活动中,就像在第一个活动中一样)

以下是第1和第2个活动的代码 第一个活动类

    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 - First Activity

<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"
    />

1 个答案:

答案 0 :(得分:0)

我只想重新创建应用。我不认为将原始文件复制到另一个目录并使用它是明智的决定。