외부 db에 저장 되어있는 텍스트, 이미지를 다 불러왔는데요
(외부db : 오라클)
edittext 검색해서 이 가져온 이름과 같으면 그 화면만 보이게 할려고했는데
이 가져온값하고 정확히 입력해야 검색이 됩니다.
예를들어 ,, 가나다를 검색하면 가나다에 대한 상품이나오고
가나, 나다 이런 상품은 안나온다는거죠...
부분검색이라고 해야 맞는 말인지 잘 모르겟는데
이거 비교할때 어떤식으로 비교하면 좋을까요 ? 부분적으로 검색이되게..
contains 라는 메서드가 있습니다.
object.contains("찌개") 와 같이 사용하면 됩니다.
직접 해당 메서드를 만들어 쓰는 방법도 검색속도/방식에 대한 개선이 가능하겠지만
equal 보다는 contains 를 사용한다면 위와같은 것은 어느정도 해결될것 같습니다.
public boolean contains (CharSequence cs)
Determines if this String contains the sequence of characters in the CharSequence passed.
Parameters
| cs | the character sequence to search for. |
|---|
Returns
trueif the sequence of characters are contained in this string, otherwisefalse.
답변 감사합니다^^
equals대신에 contains를 써보았으나 별 차이는 없는것 같네요.
sbt.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
for(int j = 0; j < Integer.parseInt(hm.get("count")); j++){
String aa = hm.get("name[" + j +"]");
String bb = search.getText().toString();
if(bb.contains(aa)){
try {
URL url = new URL("hm.get("img[" + j + "]"));
tv.setText(hm.get("name[" + j +"]"));
URLConnection conn = url.openConnection();
conn.connect();
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
iv.setImageBitmap(bm);
} catch (Exception e) {
e.printStackTrace();
}
i = j; //여기서 보이는 i는 onCreate안에 카운트하는 i 입니다.
search.setText("");
break;
}
}
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(search.getWindowToken(), 0);
}
});
소스 코드의 일부분입니다.
sbt는 버튼객체고요..




정확해야 하면 그냥 equal로 하면 되지 않나요?