我有一个Fragment
,里面有一个ListView
。现在我正在AsyncTask
使用doInBackGround()
. 现在我想借助ArrayAdapter
in将这些数据设置onPostExecute()
到里面的 ListView 中Fragment
。如何在里面添加数据ListView
,里面是Fragment
什么?
这是造成问题,因为我Fragment
没有Context
.
package com.example.the_hindu_news;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class Async_list extends AsyncTask<Context, Integer, String> {
private Internet_list ob_il;
private String[] news;
private String[] link;
ListView ls;
Base_class ob_bc;
public Async_list(ListView ls, Base_class ob_bc) {
this.ls = ls;
this.ob_bc = ob_bc;
}
/**
* {@inheritDoc}
*/
@Override
protected String doInBackground(Context... params) {
try {
ob_il = new Internet_list();
ob_il.parser();
ob_il.parse_VIA_pull_parser();
news = ob_il.return_news();
link = ob_il.return_links();
} catch (final Exception err) {
Log.i("doInBackGround() : " + err.toString(), "tushar");
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
protected void onPostExecute(String result) {
try {
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(ob_bc,
android.R.layout.simple_list_item_1, news);
ls.setAdapter(adapter);
} catch (final Exception err) {
Log.i("onPostExecute() : " + err.toString(), "tushar");
}
}
}