Java 从一个EditText检索多个变量

Java 从一个EditText检索多个变量,java,android,android-fragments,android-edittext,Java,Android,Android Fragments,Android Edittext,我一直在努力创建一个翻译应用程序。我从数据库中检索一个数据没有问题。我想从EditText的一个条目中获取多个字符串,并在一个TextView中显示它。这是我的密码: db = new DatabaseHelper(super.getActivity()).getWritableDatabase(); searchText = (EditText) rootView.findViewById(R.id.searchText); melanauTextView = (TextView) root

我一直在努力创建一个翻译应用程序。我从数据库中检索一个数据没有问题。我想从EditText的一个条目中获取多个字符串,并在一个TextView中显示它。这是我的密码:

db = new DatabaseHelper(super.getActivity()).getWritableDatabase();

searchText = (EditText) rootView.findViewById(R.id.searchText);
melanauTextView = (TextView) rootView.findViewById(R.id.myTextView);

Button btn = (Button) rootView.findViewById(R.id.searchButton);
btn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View V) {
        cursor = db.rawQuery("SELECT * FROM translate WHERE malayText = ?", 
                             new String[]{searchText.getText().toString()});

        if ((cursor != null) && (cursor.moveToFirst()))
                    melanauTextView.setText(String.format("%s", 
                    cursor.getString(cursor.getColumnIndex("melanauText"))));

    }
}

任何建议或观点都将不胜感激。

我认为您应该使用“搜索视图”而不是“编辑文本”。看到这一点,您必须使用cursor.moveToNext循环搜索结果,直到有行为止。但是您需要一个ListView或类似的视图组来列出多个结果,不是吗?@DerGolem我可以使用此代码修改现有代码吗?不需要。您需要一个循环来循环返回的行,以填充适配器或使用游标适配器,游标适配器将被分配给ListView。