hamedg1366
سه شنبه 16 تیر 1394, 13:25 عصر
کلافم کرده
اگه EditText رو از حالت کامنت دربیارم خطای Nullpointer میده
کدهای اکشن بار :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/search"
android:orderInCategory="100"
yourapp:showAsAction="ifRoom|collapseActionView"
android:icon="@drawable/phone"
android:title="Search"
android:actionLayout="@layout/actionbar_search_layout"/>
</menu>
actionbar_search_layout.xml====>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="@+id/txt_search"
style="@style/actionbar_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/actionbar_edittext"
android:inputType="text" />
</LinearLayout>
کدهای Main برای اکشن بار ___________اینجا به EditText خطای Nullpointer میده
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.items, menu);
View v = (View) menu.findItem(R.id.search).getActionView();
EditText txtSearch = ( EditText ) v.findViewById(R.id.txt_search);
txtSearch.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Toast.makeText(getBaseContext(), "Search : " + v.getText(), Toast.LENGTH_SHORT).show();
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
اگه EditText رو از حالت کامنت دربیارم خطای Nullpointer میده
کدهای اکشن بار :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/search"
android:orderInCategory="100"
yourapp:showAsAction="ifRoom|collapseActionView"
android:icon="@drawable/phone"
android:title="Search"
android:actionLayout="@layout/actionbar_search_layout"/>
</menu>
actionbar_search_layout.xml====>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText
android:id="@+id/txt_search"
style="@style/actionbar_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/actionbar_edittext"
android:inputType="text" />
</LinearLayout>
کدهای Main برای اکشن بار ___________اینجا به EditText خطای Nullpointer میده
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.items, menu);
View v = (View) menu.findItem(R.id.search).getActionView();
EditText txtSearch = ( EditText ) v.findViewById(R.id.txt_search);
txtSearch.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Toast.makeText(getBaseContext(), "Search : " + v.getText(), Toast.LENGTH_SHORT).show();
return false;
}
});
return super.onCreateOptionsMenu(menu);
}