-2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/llist"
tools:context="com.android.parteek.contentprovider.Main2Activity">
<android.support.v7.widget.SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/serch">
</android.support.v7.widget.SearchView>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.android.parteek.contentprovider.Main2Activity">
</ListView>
</LinearLayout>
코드
package com.android.parteek.contentprovider;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class Main2Activity extends AppCompatActivity implements AdapterView.OnItemLongClickListener, SearchView.OnQueryTextListener {
ListView l;
ArrayList<Bean> arrayList;
UserAdapterr userAdapterr;
ContentResolver contentResolver;
SearchView searchView;
Bean b,b1;
int pos;
void views(){
l=(ListView)findViewById(R.id.list);
searchView=(SearchView)findViewById(R.id.serch);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
views();
contentResolver=getContentResolver();
retrieve();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.searchmenu,menu);
searchView=(SearchView)menu.findItem(R.id.search).getActionView();
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(this);
searchView.setQueryHint("search.....");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
}
오류
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.SearchView.setIconifiedByDefault(boolean)' on a null object reference
at com.android.parteek.contentprovider.Main2Activity.onCreateOptionsMenu(Main2Activity.java:147)
을 제거 할 수있다 (SearchView) ... '올바른 그림을 찾으십시오 –