I need to add button to ArrayList
and listener to the button dynamically in for loop
. In for loop i am adding listing dynamically to ArrayList
and displaying it on the screen.Any suggestions please.
public class Details extends ListActivity {
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter;
JSONArray all=new JSONArray();
String size;
String result = "";
InputStream is=null;
public static final String MyPREFERENCES = "MyPrefs" ;
SharedPreferences sharedpreferences;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_details);
adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listItems);
setListAdapter(adapter);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://rtotv.com/Details.jsp");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
all=json_data.getJSONArray("res");
listItems.add(" \n Event Name :"+all.get(1)+" \n Location :"+all.get(2)+"\n "+all.get(3)+"\n Contact person :"+all.get(4)+"\n Start Date :"+all.get(7)+"\n End Date :"+all.get(8)+"\n Description :"+all.get(6));
}
}
}