繁体   English   中英

接口不被称为android

[英]Interface is not being called android

我使用了一个界面来确定异步任务完成与否的天气。但是当我使用该界面时,该界面的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();

    }

在这个活动中为什么我的界面没有被调用???

在这个活动中为什么我的界面没有被调用???

因为当MyResourceMatchingJobs活动未运行时调用getMatchingJobs

因此,尝试从onPostExecute启动MyResourceMatchingJobs Activity后调用这两个方法。

建议:因为发送arrayMatchingJobs和一个布尔值,所以使用i.putExtra(KEY,VALUE)获取MyResourceMatchingJobs活动中的两个值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM