Twitter検索機能を実装するAndroidベースのアプリを構築しています。ボタンのクリックは最初のみ機能します。検索語を変更してもう一度ボタンをクリックすると、更新に失敗します。誰でも私にヒントを与えることができますか?`public class TwitterSActivity extends Activity implements OnClickListener{ EditText etQuery; ボタン btnQuery;
class Tweet{
public String username;
public String message;
public String image_url;
}
ArrayList<Tweet> tweets = new ArrayList<Tweet>();
@Override
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
etQuery = (EditText) findViewById (R.id.et);
btnQuery = (Button) findViewById (R.id.btn);
btnQuery.setOnClickListener(this);
}
@Override
public void onClick(View v){
if(v.getId() == R.id.btn){
Toast.makeText(this, "Query submitted", Toast.LENGTH_LONG).show();
Getdata getdata = new Getdata();
String returned = null;
String searchTerm = etQuery.getText().toString();
try {
returned = getdata.getInternetData(searchTerm);
} catch (Exception e) {
e.printStackTrace();
}
try{
JSONObject jo = new JSONObject(returned);
JSONArray ja = jo.getJSONArray("results");
for(int i=0; i<ja.length(); i++){
JSONObject job = ja.getJSONObject(i);
Tweet tt = new Tweet();
tt.username = job.getString("from_user");
tt.message = job.getString("text");
tt.image_url = job.getString("profile_image_url");
tweets.add(tt);
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data: "+e.toString());
}
ListView lv = (ListView) findViewById(R.id.listView1);
class FancyAdapter extends ArrayAdapter<Tweet> {
public FancyAdapter() {
super(TwitterSActivity.this, android.R.layout.simple_list_item_1, tweets);
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
if(convertView == null){
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.listitem, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
holder.populatefrom(tweets.get(position));
return(convertView);
}
class ViewHolder {
public TextView username = null;
public TextView message = null;
public ImageView image = null;
ViewHolder(View listitem){
username = (TextView)listitem.findViewById(R.id.username);
message = (TextView)listitem.findViewById(R.id.message);
image = (ImageView)listitem.findViewById(R.id.avatar);
}
void populatefrom(Tweet t){
username.setText(t.username);
message.setText(t.message);
image.setImageBitmap(getBitmap(t.image_url));
}
}
}
FancyAdapter ar = new FancyAdapter();
lv.setAdapter(ar);
}
}
public Bitmap getBitmap(String bitmapUrl) {
try {
URL url = new URL(bitmapUrl);
return BitmapFactory.decodeStream(url.openConnection().getInputStream());
}
catch(Exception e) {return null;}
}`