use android carga dinámicamente más elementos a la vista de lista necesita ayuda
package fshizzle.com;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleAdapter.ViewBinder;
import android.widget.Toast;
public class welcome extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent sender=getIntent();
String login = sender.getStringExtra("extra_login");
setContentView(R.layout.listplaceholder);
ArrayList<HashMap<String, Object>> mylist = new ArrayList<HashMap<String, Object>>();
JSONObject json = JSONfunctions.getJSONfromURL(var_global.URL+"json/listview/"+login+".json");
try{
JSONArray earthquakes = json.getJSONArray("infos");
for(int i=0;i<earthquakes.length();i++){
HashMap<String, Object> map = new HashMap<String, Object>();
JSONObject e = earthquakes.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("name", "infos name:" + e.getString("user"));
map.put("age", "age: " + e.getString("age"));
URL pictureURL = new URL(var_global.URL+"upload/thumbs/"+e.getString("image"));
Bitmap bitmap = BitmapFactory.decodeStream(pictureURL.openStream());
map.put("img",bitmap);
//http://www.imagemagick.org/Usage/thumbnails/
mylist.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SimpleAdapter adapter = new SimpleAdapter(this, mylist, R.layout.json2, new String[] { "img", "name", "age" },
new int[] { R.id.item_img, R.id.item_title, R.id.item_subtitle });
adapter.setViewBinder(new MyViewBinder());
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(welcome.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
public class MyViewBinder implements ViewBinder {
public boolean setViewValue(View view, Object data,String textRepresentation) {
if( (view instanceof ImageView) & (data instanceof Bitmap) ) {
ImageView iv = (ImageView) view;
Bitmap bm = (Bitmap) data;
iv.setImageBitmap(bm);
return true;
}
return false;
}
}
}
este analiza un archivo json y crea una vista de lista con la imagen web, me gustaría usar este código pero no puedohttp: //p-xr.com/android-tutorial-dynamicaly-load-more-items-to-the-listview-never-ending-list
alguien más experimentado puede decirme cómo pegar todo esto? gracias no puedo mostrar la información de mis archivos json con el código en la url
también pruebo este códigohttp: //benjii.me/2010/08/endless-scrolling-listview-in-android pero este error "El método setOnScrollListener (welcome.EndlessScrollListener) no está definido para el tipo SimpleAdapter" con
adapter.setOnScrollListener(new EndlessScrollListener());
setListAdapter(adapter);
código
Con este código:
this.getListView().setOnScrollListener(new EndlessScrollListener());
no hay error pero todo se muestra al mismo tiempo. ????
¿Qué función LoadGigsTask ()? uso // LoadGigsTask no está definido en un tutorial, tal vez es por eso, ¿no?
está bien en código con
((AbsListView) this.view).setOnScrollListener(new EndlessScrollListener());
Pero en el emulador se bloquea en esta línea ...
Finaly uso esto, busco actualizar la vista de lista ahora ...
this.getListView().setOnScrollListener(new OnScrollListener(){
//useless here, skip!
public void onScrollStateChanged(AbsListView view, int scrollState) {}
//dumdumdum
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
//what is the bottom iten that is visible
int lastInScreen = firstVisibleItem + visibleItemCount;
//is the bottom item visible & not loading more already ? Load more !
if((lastInScreen == totalItemCount) && !(loadingMore)){
Toast.makeText(getApplicationContext(), "OK END LIST.", Toast.LENGTH_LONG).show();
//Thread thread = new Thread(null, loadMoreListItems);
//thread.start();
}
}
});