我使用了一个界面来确定异步任务完成与否的天气。但是当我使用该界面时,该界面的2个方法没有被调用。
自定义适配器类
public class MyResourceCustomAdaper extends BaseAdapter {
static GetMatchingJobsArray getMatchingJobsArray;
public MyResourceCustomAdaper(Context context, ArrayList<HashMap<String, String>> data) {
this.context = context;
this.data = data;
}
public static void setInterface(GetMatchingJobsArray getMatchingJobsArray) {
MyResourceCustomAdaper.getMatchingJobsArray = getMatchingJobsArray;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int i) {
return data.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
doing stuffs here
return view;
}
}
public static class GetMatchingJobsAsync extends AsyncTask<String, String, String> {
String response;
Context c;
public GetMatchingJobsAsync(Context c) {
this.c = c;
}
@Override
protected String doInBackground(String... strings) {
calling web method here
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
arrayMatchingJobs = new ArrayList<HashMap<String, String>>();
getMatchingJobsArray.getMatchingJobs(true, arrayMatchingJobs);// here i am passing my array to the interface
getMatchingJobsArray.hasCompleted(true);
Intent i = new Intent(c, MyResourceMatchingJobs.class);
c.startActivity(i);
}
}
}
public interface GetMatchingJobsArray {
public void getMatchingJobs(boolean value, ArrayList<HashMap<String, String>> arrayMatchingJobs);
public void hasCompleted(boolean value);
}
}
我正在实现接口的类
public class MyResourceMatchingJobs extends Activity implements MyResourceCustomAdaper.GetMatchingJobsArray {
private ListView listView;
private MyResourceMatchingJobsCustomList adapter;
private static ProgressDialog pDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_resource_matching_jobs_list);
listView = (ListView) findViewById(R.id.lv_my_resource_matching_jobs);
MyResourceCustomAdaper.setInterface(this);//use for initailizing the interface
}
@Override
public void getMatchingJobs(boolean value, ArrayList<HashMap<String, String>> arrayMatchingJobs) {
adapter = new MyResourceMatchingJobsCustomList(MyResourceMatchingJobs.this, arrayMatchingJobs);
listView.setAdapter(adapter);
}
@Override
public void hasCompleted(boolean value) {
Toast.makeText(this, "Hello", Toast.LENGTH_SHORT).show();
}
在此活动中,为什么我的界面没有被调用???
答案 0 :(得分:0)
在此活动中,为什么我的界面没有被调用???
因为getMatchingJobs
活动未运行时调用MyResourceMatchingJobs
。
因此,请从MyResourceMatchingJobs
开始onPostExecute
活动后尝试调用这两种方法。
建议:因为发送arrayMatchingJobs
和一个布尔值,所以使用i.putExtra(KEY,VALUE)
获取MyResourceMatchingJobs
活动中的两个值