嘿,MainActivity中onPostExecute(string result)方法爆出了一個錯誤:
"The method setListAdapter(CustomAdapter) is undefined for the type MainActivity.getTweets"
MainActivity.java
public class Main Activity extends Activity {
ArrayList<TweetDetailClass> tweets = new ArrayList<TweetDetailClass>();
protected void onCreate(Bundle savedInstanceState) { .. }
public boolean onCreateOptionsMenu(Menu menu) { .. }
public void searchTwitter(View view){
...
new GetTweets().execute(searchURL);
}
public class GetTweets extends AsyncTask<String, Void, String>{
protected String doInBackground(String... twitterURL){ .. }
protected void onPostExecute(String result) {
setListAdapter(new CustomAdapter(MainActivity.this, R.layout.listview, tweets));
}
}
}
CustomAdapter Constructor 中的代碼如下:
CustomAdapter(Context c, int textView, ArrayList<TweetDetailClass> data){
//_data = data;
//_c = c;
super(c, textView, data);
this._data = data;
}
setListAdapter()
只有在Activity 繼承ListActivity時才能用。你的xml布局文件肯定包含ListView 對象,id是 "@android:id/list"
。
如果滿足繼承條件的話,可以這樣
yourListView.setAdapter(new CustomAdapter(MainActivity.this, R.layout.listview, tweets));