Ich möchte Vorschläge AutocompleteTextView von SQL zeigen. Ich debugge meinen Code und ich sehe, dass, wenn ich ein Zeichen in AutocompleteTextView schreibe, Wert in nMAcDetailID und cMachineName kommen. Jetzt möchte ich eine Vorschlagsliste zeigen. Wie kann ich das erreichen?AutoCompleteTextView Vorschläge nicht angezeigt
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);
}
}
siehe meine Antwort [hier] (http://stackoverflow.com/a/19860624/2252830) – pskink
Danke pskink. Wenn ich einen Wert aus AutocompleteTextView auswähle, wird {NAME = ASJ 111, ID = 106005} in meiner AutocompleteTextView angezeigt. Ich möchte nur "ASJ 111" zeigen. –
hast du den Link versucht, den ich gepostet habe? – pskink