2 lantianyiming lantianyiming 于 2013.05.02 13:38 提问

MainActivity中的setListAdapter

嘿,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;
}

1个回答

loveiflower
loveiflower   2013.05.02 17:41
已采纳

setListAdapter()只有在Activity 继承ListActivity时才能用。你的xml布局文件肯定包含ListView 对象,id是 "@android:id/list"

如果满足继承条件的话,可以这样

yourListView.setAdapter(new CustomAdapter(MainActivity.this, R.layout.listview, tweets));

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!