Show data in listview with Asynctask

后端 未结 2 1291
滥情空心
滥情空心 2021-01-23 07:42

I success show my data from web service JSON in listview, but I want to add Asyntask. Where I can put code Asyntask in my code.

This my code to show data in list

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-23 08:24

    Working ASyncTask tutorial,

    Full ASyncTask Eclipse Project,

    and here's some code that I think, when mixed with the above sample, will get you the result with the list that you desire (you'll have to adapt it to your needs a bit, though (pay attention to the list stuff, even though this is from a custom Dialog:

        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle("Kies Facebook-account");
            builder.setNegativeButton("Cancel", this);
            LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View dialogLayout = inflater.inflate(R.layout.dialog, null);
            builder.setView(dialogLayout);
    
            final String[] items = {"Red", "Green", "Blue" };
    
            builder.setAdapter(new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, items), 
                    new DialogInterface.OnClickListener() {
    
    
                public void onClick(DialogInterface dialog, int which) {
                    Log.v("touched: ", items[which].toString());
    
                }} 
                );
    
    
            return builder.create();
    
        }
    

提交回复
热议问题