Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android onListItemClick可单击,但不能转到其他活动_Android_Android Studio_Listactivity - Fatal编程技术网

Android onListItemClick可单击,但不能转到其他活动

Android onListItemClick可单击,但不能转到其他活动,android,android-studio,listactivity,Android,Android Studio,Listactivity,单击项目时无法转到其他活动。 这是我使用的代码: public class SearchCustomListViewActivity extends ListActivity{ ArrayList<HashMap<String, Object>> searchResults; ArrayList<HashMap<String, Object>> originalValues; LayoutInflater inflater; ListVi

单击项目时无法转到其他活动。 这是我使用的代码:

public class SearchCustomListViewActivity extends ListActivity{


ArrayList<HashMap<String, Object>> searchResults;


ArrayList<HashMap<String, Object>> originalValues;
LayoutInflater inflater;

ListView HRListView;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.search_custom_list_view);
    String names[]= new String[]{
            "Artina Suites Hotel",
            "Casa Bocobo Hotel",
            "Hotel H2O",
            "Hotel Jen Manila",
            "Luxent Hotel",
            "Oakwood Premier Joy-Nostalg Center Manila",
            "Sofitel Philippine Plaza Manila",
            "The Bayleaf"
    };
    final EditText searchBox=(EditText) findViewById(R.id.searchBox);
    HRListView=(ListView) findViewById(android.R.id.list);


    inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    Integer[] photos={R.drawable.man_ho,R.drawable.man_pen,
            R.drawable.bag_aza,R.drawable.bor_fri,
            R.drawable.dav_mar,R.drawable.pal_pab,
            R.drawable.man_pen,R.drawable.man_ho};

    originalValues=new ArrayList<HashMap<String,Object>>();


    HashMap<String , Object> temp;


    int noOfPlayers=names.length;


    for(int i=0;i<noOfPlayers;i++)
    {
        temp=new HashMap<String, Object>();

        temp.put("name", names[i]);
        temp.put("photo", photos[i]);

        //add the row to the ArrayList
        originalValues.add(temp);
    }

    searchResults=new ArrayList<HashMap<String,Object>>(originalValues);


    final CustomAdapter adapter=new CustomAdapter(this, R.layout.list_layout,searchResults);


    HRListView.setAdapter(adapter);

    searchBox.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before, int count) {

            String searchString = searchBox.getText().toString();
            int textLength = searchString.length();
            searchResults.clear();

            for (int i = 0; i < originalValues.size(); i++) {
                String playerName = originalValues.get(i).get("name").toString();
                if (textLength <= playerName.length()) {

                    if (searchString.equalsIgnoreCase(playerName.substring(0, textLength)))
                        searchResults.add(originalValues.get(i));
                }
            }

            adapter.notifyDataSetChanged();
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {

        }

        public void afterTextChanged(Editable s) {

        }
    });

    }


    private class CustomAdapter extends ArrayAdapter<HashMap<String, Object>>
{

    public CustomAdapter(Context context, int textViewResourceId,
                         ArrayList<HashMap<String, Object>> Strings) {


        super(context, textViewResourceId, Strings);
    }

    private class ViewHolder
    {
        ImageView photo;
        TextView name,team;
    }

    ViewHolder viewHolder;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView==null)
        {
            convertView=inflater.inflate(R.layout.list_layout, null);
            viewHolder=new ViewHolder();

            viewHolder.photo=(ImageView) convertView.findViewById(R.id.photo);
            viewHolder.name=(TextView) convertView.findViewById(R.id.name);


            convertView.setTag(viewHolder);

        }
        else
            viewHolder=(ViewHolder) convertView.getTag();


        int photoId=(Integer) searchResults.get(position).get("photo");

   viewHolder.photo.setImageDrawable(getResources().getDrawable(photoId));
        viewHolder.name.setText(searchResults.get(position).get("name").toString());


        return convertView;
    }
}

}

我认为,如果它不起作用,您可以通过删除

selected.trim()


它将只匹配它是否包含指定的字符串。因此,您不必担心空格等问题。

Log.dListItemClick、selected.trim;在你的日志上打印出来?如果愿意,您可以将最终的静态字符串值作为标记。您正在HashMap上调用toString,它不会返回您想要的内容。将适配器项强制转换为HashMap并检索hashMapItem.getname.toString。谢谢!感谢你们所有人:
selected.trim()
selected.contains(("Artina Suites Hotel"); etc