SQLからAutocompleteTextViewの提案を表示したい。私は自分のコードをデバッグし、autocompleteTextViewに文字を書き込むと、値がnMAcDetailIDとcMachineNameに来ることがわかります。今私は提案リストを表示したい。どうすればこれを達成できますか?AutoCompleteTextViewの提案が表示されない
SimpleAdapter ADAhere;
List<Map<String, String>> data = null;
txtMachineName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
private Timer timer=new Timer();
private final long DELAY = 300; // milliseconds
@Override
public void afterTextChanged(Editable s) {
timer.cancel();
timer = new Timer();
timer.schedule(
new TimerTask() {
@Override
public void run() {
// TODO: do what you need here (refresh list)
// you will probably need to use runOnUiThread(Runnable action) for some specific actions
new async_fillMachineName().execute();
}
},
DELAY
);
}
});
class async_fillMachineName extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try {
Connection con = connectionClass.CONN();
if (con == null) {
getActivity().getParent().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity(), "please Check Your Internet Connection", Toast.LENGTH_LONG).show();
}
});
} else {
@SuppressWarnings("WrongThread") String query = "exec App_ac_MacName "+nClintID+",'"+txtMachineName.getText()+"'";
ResultSet rs = dbHelp.executeRS(query);
data = new ArrayList<Map<String, String>>();
try {
while (rs.next()) {
Map<String, String> datanum = new HashMap<String, String>();
datanum.put("ID",rs.getString("nMAcDetailID"));
datanum.put("NAME", rs.getString("cMachineName"));
data.add(datanum);
String str;
str = "1";
}
} catch (SQLException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return resultClientID;
}
@Override
protected void onPostExecute(String result1) {
try {
String[] fromwhere = {"ID","NAME"};
int[] viewswhere = {R.id.nSerialMachineID,R.id.cCodeMachineNAme};
ADAhere = new SimpleAdapter(getActivity(), data, R.layout.machine_autocomplete_list_template, fromwhere, viewswhere);
//SimpleCursorAdapter a = new SimpleCursorAdapter(getActivity(), R.layout.machine_autocomplete_list_template, null, fromwhere, viewswhere, 0);
//a.setStringConversionColumn(1);
txtMachineName.setAdapter(ADAhere);
} catch (Exception e) {
}
super.onPostExecute(result1);
}
}
私の答えを見る[ここ](http://stackoverflow.com/a/19860624/2252830) – pskink
ありがとうpskink。 AutocompleteTextViewから任意の値を選択すると、AutocompleteTextViewに{NAME = ASJ 111、ID = 106005}が表示されます。私は "ASJ 111"だけを見せたい。 –
投稿したリンクを試しましたか? – pskink