Hallo zusammen.
Ich würde gerne mein Listview Filtern, jedoch stürzt die ab mit folgender Begründung ab:
Hier noch der Code:
Kann mir jemand helfen?
Ich würde gerne mein Listview Filtern, jedoch stürzt die ab mit folgender Begründung ab:
Quellcode
- 4362-4362/test_app.com.bmu_app E/InputEventSender﹕ Exception dispatching finished signal.
- 03-18 12:35:14.216 4362-4362/test_app.com.bmu_app E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
- 03-18 12:35:14.217 4362-4362/test_app.com.bmu_app E/MessageQueue-JNI﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'android.widget.Filter android.widget.ArrayAdapter.getFilter()' on a null object reference
- at test_app.com.test_app.menu4_Fragment$1.onTextChanged(menu4_Fragment.java:66)
Hier noch der Code:
Java-Quellcode
- import android.app.ProgressDialog;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- import android.widget.TextView;
- import android.widget.Toast;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- /**
- * Created by Roger on 11.03.2015.
- */
- public class menu4_Fragment extends Fragment {
- View rootview;
- ListView list;
- TextView ver;
- TextView name;
- TextView api;
- Button Btngetdata;
- ArrayList<HashMap<String, String>> oslist = new ArrayList<HashMap<String, String>>();
- //URL to get JSON Array
- private static String url = "http://192.168.61.5/androidapp/anlagen_verzeichniss.php";
- //JSON Node Names
- private static final String TAG_OS = "android";
- private static final String TAG_VER = "AnlagenNr";
- private static final String TAG_NAME = "ProjektBezeichnung";
- private static final String TAG_API = "ProjektBezeichnung";
- JSONArray android = null;
- private List<String> originalData = null;
- private List<String>filteredData = null;
- private ArrayAdapter simpleAdapter;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- rootview = inflater.inflate(R.layout.menu4_layout, container, false);
- final ListView listview = (ListView) rootview.findViewById(R.id.listView1);
- final EditText inputSearch = (EditText) rootview.findViewById(R.id.inputSearch);
- new JSONParse().execute();
- oslist = new ArrayList<HashMap<String, String>>();
- inputSearch.addTextChangedListener(new TextWatcher() {
- @Override
- public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
- // When user changed the Text
- menu4_Fragment.this.simpleAdapter.getFilter().filter(cs);
- }
- @Override
- public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
- int arg3) {
- // TODO Auto-generated method stub
- }
- @Override
- public void afterTextChanged(Editable arg0) {
- // TODO Auto-generated method stub
- }
- });
- return rootview;
- }
- private class JSONParse extends AsyncTask<String, String, JSONObject> {
- private ProgressDialog pDialog;
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- //ver = (TextView)rootview.findViewById(R.id.vers);
- name = (TextView)rootview.findViewById(R.id.name);
- api = (TextView)rootview.findViewById(R.id.api);
- pDialog = new ProgressDialog(getActivity());
- pDialog.setMessage("Daten werden Geladen ...");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- pDialog.show();
- }
- @Override
- protected JSONObject doInBackground(String... args) {
- JSONParser jParser = new JSONParser();
- // Getting JSON from URL
- JSONObject json = jParser.getJSONFromUrl(url);
- return json;
- }
- @Override
- protected void onPostExecute(JSONObject json) {
- pDialog.dismiss();
- try {
- // Getting JSON Array from URL
- android = json.getJSONArray(TAG_OS);
- for(int i = 0; i < android.length(); i++){
- JSONObject c = android.getJSONObject(i);
- // Storing JSON item in a Variable
- String ver = c.getString(TAG_VER);
- String name = c.getString(TAG_NAME);
- String api = c.getString(TAG_API);
- // Adding value HashMap key => value
- HashMap<String, String> map = new HashMap<String, String>();
- map.put(TAG_VER, ver);
- map.put(TAG_NAME, name);
- map.put(TAG_API, api);
- oslist.add(map);
- list=(ListView)rootview.findViewById(R.id.listView1);
- ListAdapter adapter = new SimpleAdapter(getActivity(), oslist,
- R.layout.list_v,
- new String[] { TAG_VER,TAG_NAME, TAG_API }, new int[] {
- R.id.name, R.id.api});
- list.setAdapter(adapter);
- list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- Toast.makeText(getActivity(), "You Clicked at " + oslist.get(position).get("AnlagenNr"), Toast.LENGTH_SHORT).show();
- }
- });
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- }
Kann mir jemand helfen?