setListAdapter within MainActivity

Hi I'm trying to get my listview to work with json and in my MainActivity. I have an error on my onPostExecute(string result) method. It gives me the following error: "The method setListAdapter(CustomAdapter) is undefined for the type MainActivity.getTweets". I have the following:

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

Thanks for your help! I'm a beginner so any help would be greatly appreciated!

Answers


setListAdapter() can only be used if your Activity extends ListActivity and I think your xml layout must contain a ListView object with the id "@android:id/list".

Alternativelly, if your Activity extends Activity you should set the adapter like:

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

Let me know if it helps!


setListAdapter() is a method on ListActivity. Your activity (whose name apparently is the invalid Main Activity) appears to inherit from Activity, not ListActivity.


Need Your Help

Should I use a GZIP compression middleware or not?

google-app-engine wsgi

Having worked with Django, I've seen that people tend to reccommend the use of GZIP Middleware to compress HTML pages.

Why won't my DataContext use SQL Server Compact Edition 4, rather than trying to use 3.5?

linq-to-sql asp.net-mvc-2 sql-server-ce sql-server-ce-4

I'm playing around with SQL Server Compact Edition 4 CTP1 as I'd like to use it as a datastore for a low-traffic web app. When I try to create a DataContext with a connection string specifying

A Cocoa API for Preview?

osx cocoa api preview

Is there an API which allows us to integrate with the Preview app in OS X? Sort of what Adobe is offering for the Reader. I need to be able to read the text from PDF files and also highlight it.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.