我真的很困惑如何将 ArrayList 发送到不同的类,我有一个名为 = AgenList 的 ArrayList,我想将它发送到扩展 BaseAdapter 的不同类,有没有人可以帮助我解决我的问题..?这是我的源代码: 1. MainActivity.java
public class MainActivity extends Activity {
List AgenList = new ArrayList();
boolean boolStatusKoneksi=true;
private ProgressDialog Dialog;
protected Context applicationContext;
@Override
public void onCreate(Bundle savedInstanceState){
new AgenAsyncTask().execute();
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new TesAdapter(this));
}
public class AgenAsyncTask extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
Dialog = new ProgressDialog(MainActivity.this);
Dialog.setMessage("Mohon Tunggu sebentar...");
Dialog.setIndeterminate(false);
Dialog.setCancelable(true);
Dialog.show();
}
protected String doInBackground(String... args) {
String url = ("http://www.abc.com/xyz.php");
try{
JSONParser j=new JSONParser();
JSONArray jsonArray = j.takeJson(url);
for(int i =0; i<jsonArray.length(); i++)
{
JSONObject c = jsonArray.getJSONObject(i);
HashMap<String, String> map = new HashMap<String, String>();
if (c.has("atasan"))
map.put("atasan", c.get("atasan").toString());
if (c.has("nama_agen"))
map.put("nama_agen", c.get("nama_agen").toString());
if (c.has("kode_agen"))
map.put("kode_agen", c.get("kode_agen").toString());
if (c.has("no_aaji"))
map.put("no_aaji", c.get("no_aaji").toString());
if (c.has("jenis"))
map.put("jenis", c.get("jenis").toString());
AgenList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String arg) {Dialog.dismiss();}
如您所见,我有一个名为 AgenList 的数组列表,其中包含我想发送到 TesAdapter.java 的 JSONArray,所以这是 TesAdapter.java:
public class TesAdapter extends BaseAdapter{
private LayoutInflater layout;
public TesAdapter(MainActivity context) {
layout = LayoutInflater.from(context);
List AgenList = new ArrayList();
}
@Override
public int getCount() {
return (Integer) null;
}
@Override
public Object getItem(int position) {
return 0;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
convertView= layout.inflate(R.layout.list_item,parent,false);
holder = new ViewHolder();
holder.ATASAN = (TextView) convertView.findViewById(R.id.atasan);
holder.NAMA_AGEN= (TextView) convertView.findViewById(R.id.nama_agen);
holder.KODE_AGEN= (TextView)convertView.findViewById(R.id.kode_agen);
holder.NO_AAJI= (TextView) convertView.findViewById(R.id.no_aaji);
holder.JENIS= (TextView) convertView.findViewById(R.id.jenis);
return convertView;
}
}
class ViewHolder{
TextView ATASAN;
TextView NAMA_AGEN;
TextView KODE_AGEN;
TextView NO_AAJI;
TextView JENIS;
}
我希望有人可以帮助我解决这个问题,谢谢