我对自定义列表视图中的异步 http 调用有疑问。如何在我的以下自定义 Listview 中调用异步调用并解析 json 以填充 Listview 。我的自定义列表视图包含来自图像和文本。
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.Menu;
import android.view.View;
import android.widget.ListView;
public class ListActivityS extends ListActivity
{
private GetHttpCall getCall;
String item[];
int id[];
ArrayList<Video> videos;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
//Crearte instance to http call
getCall=new GetHttpCall();
String response=null;
try {
response=getCall.connect();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONParser _parser=new JSONParser();
_parser.parseHttpJson(response);
item = JSONParser.num_title;
id=JSONParser.num_id;
videos=new ArrayList<Video>();
for(int i=0;i<item.length;i++)
{
Video vid=new Video();
vid.setTitle(item[i]);
vid.setId(id[i]);
videos.add(vid);
}
getListView().setDividerHeight(2);
getListView().setAdapter(new BindDataAdapter(this, videos));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(item[position] + " is clicked.");
builder.setPositiveButton("OK", null);
builder.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_list, menu);
return true;
}
}