簡體   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