Hi,
Sorry for the wrong code. Here is the code which has the issues I
mentioned.
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
public class YoutubeAutoComplete extends Activity {
Youtube yt = new Youtube();
CustomAutoComplete myAutoComplete;
ArrayAdapter<String> adapter;
private JSONArray js;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myAutoComplete = (CustomAutoComplete)
findViewById(R.id.autocomplete);
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line);
myAutoComplete.addTextChangedListener(textWatcher);
myAutoComplete.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
TextWatcher textWatcher = new TextWatcher() {
public void onTextChanged(final CharSequence s, int start, int
before,
int count) {
Thread t = new Thread() {
public void run() {
try {
System.out.println("in here
*******************************");
js =
yt.GetSuggestions(s.toString()).getJSONArray(1);
messageHandler.sendEmptyMessage(0);
} catch (JSONException e) {
// TODO Auto-generated catch
block
e.printStackTrace();
}
}
};
t.start();
}
public void beforeTextChanged(CharSequence s, int start, int
count,
int after) {
}
public void afterTextChanged(Editable s) {
}
};
private Handler messageHandler = new Handler() {
public void handleMessage(Message msg) {
for (int i = 0; i < js.length(); i++) {
try {
adapter.add(js.getJSONArray(i).getString(0));
System.out.println(js.getJSONArray(i).getString(0));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
adapter.notifyDataSetChanged();
}
};
}
Looking forward,
Regards,
Anees
On Oct 22, 11:25 am, Anees <[email protected]> wrote:
> Hi experts,
>
> I am trying to implement a dynamic auto complete widget in android. I
> am done with the major functionalities and the auto completion
> implemented is for youtube video search.
>
> When I start typing a letter or two, the auto-completion is not
> working. But when I type three letters or more it works prefect. It
> also works when I type two letters and hit a backspace. I do not know
> what is wrong with the code.
>
> Code is as follows
>
> import android.app.Activity;
> import android.content.Intent;
> import android.os.Bundle;
> import android.view.View;
> import android.view.View.OnClickListener;
> import android.widget.Button;
>
> public class SendUrl extends Activity {
> /** Called when the activity is first created. */
> Button button;
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
> button = (Button) findViewById(R.id.Button01);
> button.setOnClickListener(new OnClickListener() {
>
> @Override
> public void onClick(View v) {
> Intent picMessageIntent = new Intent(
> android.content.Intent.ACTION_SEND);
>
> picMessageIntent.putExtra(Intent.EXTRA_SUBJECT, "Here's a cool
> youtub video");
> picMessageIntent.putExtra(Intent.EXTRA_TEXT,
> "Go to url: "+"http://
> google.com/");
> picMessageIntent.setType("plain/text");
>
> startActivity(Intent.createChooser(picMessageIntent, "Send your
> url using:"));
> }
> });
> }
>
> }
>
> Experts, kindly guide me. I would be obliged if you can point out
> where I have gone wrong with the code.
>
> Any help in this regard will be well appreciated.
>
> Looking forward,
> Regards,
> Anees
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en