我想通过我的朋友实施推特列表推文。我的意思是我想搜索一个名字,发现推文属于那个名字。这是我使用的代码。但它没有用。
public class SearchActivity extends Activity{
TextView view;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_layout);
EditText edt=(EditText)findViewById(R.id.edt);
final String enteredText = edt.getText().toString();
Button b=(Button)findViewById(R.id.button_search);
//return enteredText + "" + new Date().toLocaleString();
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Twitter twitter = new TwitterFactory().getInstance();
Query query = new Query(enteredText);
QueryResult result=null;
try {
result = twitter.search(query);
//List<Tweet> tweets = result.getTweets();
for (Tweet tweet : result.getTweets()) {
//System.out.println(tweet.getFromUser() + ":" + enteredText);
view.setText(tweet.getFromUser() + ":" + tweet.getText());
;}}
catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Failed to search tweets: " );
}
}});}}