我學習Android的,我有這個錯誤,我不知道如何在適配器getdata()
固定爲ArrayList的
adapter = new GridViewAdapter(this, R.layout.grid_item_layout, getData());
我知道的參數解決
錯誤The constructor is undefined
適配器construtcor數組列表的Gridviewadapter的構造函數應該被修復..但是如何?
public GridViewAdapter(Context context, int layoutResourceId, ArrayList<Listitem> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.mcontext =context;
}
這是代碼
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
String id = c.getString(TAG_ID);
String url = c.getString(TAG_URL);
Listitem.add(new Listitem(id,url));
}
adapter = new GridViewAdapter(this, R.layout.grid_item_layout, getData());
list.setAdapter(adapter);
的GetData()
公共無效的getData(){ 類GetDataJSON擴展的AsyncTask {
@Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://justedhak.comlu.com/get-data.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
@Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
錯誤是由於'getData()'函數引起的,請發佈包含'getData()'功能的整個代碼。 –
@vipul_asri檢查我的編輯PLZ – Moudiz