简体   繁体   中英

Interface is not being called android

I have used a interface to determine weather the async task is finish or not.But when i use the interface,the 2 methods of that interface is not being called.

The Custom Adapter Class

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

}

}

Class where i am implementing the interface

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();

    }

Here in this activity why my interface is not being called???

Here in this activity why my interface is not being called???

Because Calling getMatchingJobs when MyResourceMatchingJobs Activity is not running.

So try to call both methods after starting MyResourceMatchingJobs Activity from onPostExecute .

Suggestion: becuase sending arrayMatchingJobs and one boolean value so use i.putExtra(KEY,VALUE) for getting both values in MyResourceMatchingJobs Activity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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