Skip to content

Instantly share code, notes, and snippets.

@rajivnarayana
Created August 2, 2014 10:41
Show Gist options
  • Save rajivnarayana/b3b5e3aa321389cdba4e to your computer and use it in GitHub Desktop.
Save rajivnarayana/b3b5e3aa321389cdba4e to your computer and use it in GitHub Desktop.
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1) {
@Override
public int getCount() {
return 40;
}
@Override
public String getItem(int position) {
return "Cell";
}
};
ListView listView = new ListView(this);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
deleteListItemAtIndex(position);
}
});
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.addView(listView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
this.setContentView(frameLayout);
}
private static final String TAG = "Volley";
public void deleteListItemAtIndex(final int index) {
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
//Make a request depending on the index
String url ="http://www.york.ac.uk/teaching/cws/wws/webpage1.html";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener() {
@Override
public void onResponse(Object o) {
android.util.Log.v(TAG, "Make changes to remove item at index: "+index + "\n"+ ((String)o).substring(0,20));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
android.util.Log.v(TAG, "Could not delete item at index "+index);
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment