如何使用分页或 loadmore 选项在 android 中添加砌体布局
示例代码是
公共无效 oncreateProduct_List(int countm) {
String testurl = URL1 + "prod/"+countm;
// String testurl = URL1 + "sandy_scandy/"+counter;
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
JsonParser jParser = new JsonParser();
JSONObject json1 = jParser.getJSONfromUrl(testurl);
try {
JSONArray prod = json1.getJSONArray("prod");
for ( i = 0; i < prod.length(); i++) {
JSONObject prd = prod.getJSONObject(i);
p_id = prd.getString("p_id");
cat_id = prd.getString("cat_id");
barcode = prd.getString("barcode");
p_name = prd.getString("p_name");
price = prd.getString("price");
desp = prd.getString("desp");
image = prd.getString("image");
status = prd.getString("status");
timestamp = prd.getString("timestamp");
cat_name = prd.getString("cat_name");
try {
bitmap = BitmapFactory.decodeStream((InputStream) new URL(image).getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
HashMap<String, String>map1= new HashMap<String, String>();
map1.put("IMAGE", image);
pro_id = p_id;
create_layout(pro_id,bitmap);
}
} catch (JSONException e) {
Log.e("error", e.toString());
}
//countm++;
}
private class LoadViewTask extends AsyncTask<Void, Integer, Void> {
// Before running code in the separate thread
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(MyShopping_List.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(false);
progressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
synchronized (this) {
int counter = 0;
while (counter <= 10) {
this.wait(300);
counter++;
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
progressDialog.setProgress(values[0]);
}
@Override
protected void onPostExecute(Void result) {
oncreateProduct_List(countm);
/*Scroll_main.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Thread.getDefaultUncaughtExceptionHandler();
Thread.yield();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new LoadViewTask().execute();
oncreateProduct_List(countm);
countm++;
}
return false;
}
}); */
progressDialog.dismiss();
}
}
并调用触摸监听器
Scroll_main.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
float yValue=event.getY();
Display display = getWindowManager().getDefaultDisplay();
int height = display.getHeight();
int scrollheight =Scroll_main.getHeight();
System.out.println("Screen Height>"+height);
System.out.println("value of scroll main ="+scrollheight);
//int ss=height-181;
//height=(height*90)/100;
if((yValue)<scrollheight){
Toast.makeText(getApplicationContext(), "Heloo"+height, Toast.LENGTH_SHORT).show();
} /*elseif((Scroll_main.getHeight()-yValue)>=height){
new LoadViewTask().execute();
oncreateProduct_List(countm);
countm = countm--;
height=height--;
} */
else{
new LoadViewTask().execute();
countm = countm ++;
oncreateProduct_List(countm);
scrollheight=scrollheight++;
}
return false;
}
});