Ich verwende Text aus einem EditText, um einige Elemente in einer Listview mithilfe eines benutzerdefinierten Adapters aus einer MySQL-Datenbank abzurufen. Mit einem Klick auf eine Schaltfläche neben dem EditText starte ich eine weitere Aktivität mit intent. Die EditText funktioniert gut, wenn th App zum ersten Mal startet und öffnet sich zu MainActivity aber der Cursor stagniert für 1-2 Sekunden, wenn MainActivity von einem anderen acivity.The Code geladen wird, ist wie folgt:EditText Verzögerung bei Aktivitätsänderung
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context="nf.co.riaah.chutte.MainActivity"
android:orientation="vertical"
android:background="#EEEEEE"
android:id="@+id/linear_main">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme= "@style/ToolbarColoredBackArrow"
android:id="@+id/app_bar"
android:minHeight="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dp"
>
<ImageView
android:layout_width="150dp"
android:layout_height="30dp"
android:src="@drawable/title"
android:id="@+id/title_image"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/oie_transparent"
android:layout_alignParentRight="true"
android:id="@+id/cart_icon"
android:layout_toRightOf="@id/title_image"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/search_area"
android:padding="5dp">
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Type Your Text Here"
android:id="@+id/gettext"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="Search"
android:layout_alignParentRight="true"
android:background="@drawable/circle"
android:textColor="#FFFFFF"
android:onClick="search_product"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/circle"
android:layout_margin="10dp"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="\?"
android:textColor="#FFFFFF"
android:textAlignment="center"
android:textSize="125dp">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"
android:textAlignment="center"
android:textSize="25dp"
android:text="About Us">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/circle"
android:layout_margin="10dp"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/re"
android:src="@drawable/home_clipart_edited"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"
android:textAlignment="center"
android:textSize="25dp"
android:text="Nearby Shops"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/circle"
android:layout_margin="10dp"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/money_clipart_edited"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"
android:textAlignment="center"
android:textSize="25dp"
android:text="Donate"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/circle"
android:layout_margin="10dp"
android:orientation="vertical"
android:onClick="goto_list">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:textColor="#FFFFFF"
android:textAlignment="center"
android:textSize="25dp"
android:text="Click Here for latest"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private EditText editText;
public static String pname;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // an example activity_main.xml is provided below
Toolbar tb = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(tb);
editText = (EditText) findViewById(R.id.gettext);
}
public void goto_list(View view) {
Intent intent = new Intent(this, Search_multiple.class);
startActivity(intent);
}
public void search_product(View view) {
Intent intent = new Intent(this, Search_multiple.class);
pname = editText.getText().toString();
startActivity(intent);
}
}
Ich benutze asynctask für Access-Datenbank in Search_multiple.class. Sollte ich es auch für die Absicht benutzen? –
@ I.Goel entfernen Sie einfach alles aus dem oncreate (opause, onstart, onrestart) der zweiten Aktivität und überprüfen, ob der Cursor stoppt, wenn es nicht Ihren Code Zeile für Zeile überprüft, wo ist der genaue Punkt, wenn der Cursor stoppt –
Ich dachte nur, dass die Tastatur beim Berühren des EditText keine Verzögerung aufweist, aber der Cursor für etwa 0,5 bis 1 Sekunde stagniert. Ist das normal oder begehe ich einen anderen Fehler? –