过滤后的ListView onItemClick会在原始位置返回Item以进行在线活动

时间:2017-05-10 02:36:16

标签: android listview listview-filter

您好我正在尝试制作一个包含target/generated-sources的{​​{1}}个list item来自suggestion的应用。但当我website其中一个项目时,它只返回第一个项目相关值。但我只希望他们Click

这是我的related value

Main Activity

这是public class MainActivity extends AppCompatActivity { ListView vl; Button b; // List view private ListView lv; // Listview Adapter ArrayAdapter<String> adapter; // Search EditText EditText inputSearch; // ArrayList for Listview ArrayList<HashMap<String, String>> news_title; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); vl = (ListView) findViewById(R.id.myList); b= (Button) findViewById(R.id.addNewbutton); inputSearch = (EditText) findViewById(R.id.inputSerach); fetchingData(); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getApplicationContext(), AddingNews.class)); } }); } void fetchingData(){ String myURL = "http://192.168.56.1/android/api/gettingnews.php"; JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(myURL, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { final String[] news_title = new String[response.length()]; final String[] news_detail = new String[response.length()]; final String[] news_time = new String[response.length()]; for (int i =0; i < response.length(); i++){ try { JSONObject jsonObject = (JSONObject) response.get(i); news_title[i] = jsonObject.getString("title"); news_detail[i] = jsonObject.getString("news"); news_time[i] = jsonObject.getString("time"); } catch (JSONException e) { e.printStackTrace(); } } // vl.setAdapter(new ArrayAdapter(getApplicationContext(), R.layout.mylistview, R.id.textViewforlist, news_title)); // Adding items to listview adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.mylistview, R.id.textViewforlist, news_title); vl.setAdapter(adapter); inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { // When user changed the Text MainActivity.this.adapter.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 } }); vl.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(MainActivity.this, Details.class); intent.putExtra("MyTitle", news_title[position]); intent.putExtra("MyNews", news_detail[position]); intent.putExtra("MyTime", news_time[position]); startActivity(intent); } }); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d("Volley Log", error); } }); com.example.forkan.tuntuninews.AppController.getInstance().addToRequestQueue(jsonArrayRequest); Toast.makeText(getApplicationContext(),"Data Loaded Successfully", Toast.LENGTH_LONG).show(); } }

My Details: activites;

我如何修复它请帮助我..

0 个答案:

没有答案