Java 接口没有被称为android
我使用了一个接口来确定异步任务是否完成。但是当我使用该接口时,该接口的两个方法没有被调用 自定义适配器类Java 接口没有被称为android,java,android,interface,Java,Android,Interface,我使用了一个接口来确定异步任务是否完成。但是当我使用该接口时,该接口的两个方法没有被调用 自定义适配器类 public class MyResourceCustomAdaper extends BaseAdapter { static GetMatchingJobsArray getMatchingJobsArray; public MyResourceCustomAdaper(Context context, ArrayList<HashMap<String
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);
}
}
公共类MyResourceCustomAdaper扩展BaseAdapter{
静态GetMatchingJobsArray GetMatchingJobsArray;
公共MyResourceCustomAdaper(上下文、ArrayList数据){
this.context=上下文;
这个数据=数据;
}
公共静态void setInterface(GetMatchingJobsArray GetMatchingJobsArray){
MyResourceCustomAdaper.getMatchingJobsArray=getMatchingJobsArray;
}
@凌驾
public int getCount(){
返回data.size();
}
@凌驾
公共对象getItem(int i){
返回数据。获取(i);
}
@凌驾
公共长getItemId(int i){
返回i;
}
@凌驾
公共视图getView(最终int i、视图视图、视图组视图组){
在这里做事
返回视图;
}
}
公共静态类GetMatchingJobsAsync扩展异步任务{
字符串响应;
上下文c;
公共GetMatchingJobsAsync(上下文c){
这个.c=c;
}
@凌驾
受保护的字符串背景(字符串…字符串){
在此处调用web方法
}
@凌驾
受保护的void onPostExecute(字符串s){
super.onPostExecute(s);
arrayMatchingJobs=新的ArrayList();
getMatchingJobsArray.getMatchingJobs(true,arrayMatchingJobs);//这里我将数组传递给接口
getMatchingJobsArray.hasCompleted(true);
意向i=新意向(c,MyResourceMatchingJobs.class);
c、 星触觉(i);
}
}
}
公共接口GetMatchingJobsArray{
public void getMatchingJobs(布尔值,ArrayList arrayMatchingJobs);
public void hasCompleted(布尔值);
}
}
类实现接口的位置
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();
}
公共类MyResourceMatchingJobs扩展活动实现MyResourceCustomAdaper.GetMatchingJobsArray{
私有列表视图列表视图;
私有MyResourceMatchingJobsCustomList适配器;
专用静态进程对话框;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.my_resource_matching_jobs_list);
listView=(listView)findViewById(R.id.lv\u我的\u资源\u匹配的\u作业);
MyResourceCustomAdaper.setInterface(this);//用于初始化接口
}
@凌驾
public void getMatchingJobs(布尔值,ArrayList arrayMatchingJobs){
adapter=new MyResourceMatchingJobsCustomList(MyResourceMatchingJobs.this,arrayMatchingJobs);
setAdapter(适配器);
}
@凌驾
已完成公共void(布尔值){
Toast.makeText(这是“Hello”,Toast.LENGTH_SHORT).show();
}
在本活动中,为什么不调用我的接口
在本活动中,为什么不调用我的接口
因为在MyResourceMatchingJobs
活动未运行时调用getMatchingJobs
因此,在从onPostExecute
启动MyResourceMatchingJobs
活动后,尝试调用这两种方法
建议:由于发送
arrayMatchingJobs
和一个布尔值,因此使用i.putExtra(KEY,value)
在MyResourceMatchingJobs
Activity@Anuj:为什么从onPostExecute
启动MyResourceMatchingJobs
活动?那么我将如何调用新活动?