Guest User

Untitled

a guest
May 20th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.46 KB | None | 0 0
  1. public class VolleyActivity extends Activity{
  2. private int lastSawFirstListItem;
  3. private int itemLoadedOn;
  4. private ArrayAdapter adapter;
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.volley_main);
  9.  
  10. Button getBtn = (Button)findViewById(R.id.btn_get_request);
  11. getBtn.setOnClickListener(new View.OnClickListener() {
  12. @Override
  13. public void onClick(View v) {
  14.  
  15. }
  16. });
  17.  
  18. ListView listView = (ListView)findViewById(R.id.volleyListView);
  19. adapter = new CustomAdapter(this,new Entity[0]);
  20. listView.setAdapter(adapter);
  21. String url = "http://api.androidhive.info/feed/feed.json";
  22.  
  23. JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
  24. @Override
  25. public void onResponse(JSONObject jsonObject) {
  26. List<Entity> items = new ArrayList<Entity>();
  27. try{
  28. JSONArray jsonArray = jsonObject.getJSONArray("feed");
  29. for(int i=0;i<jsonArray.length();i++)
  30. {
  31. JSONObject item = jsonArray.getJSONObject(i);
  32. Entity en = new Entity();
  33. en.setId(item.getInt("id"));
  34. en.setName(item.getString("name"));
  35. en.setUrl(item.getString("url"));
  36. items.add(en);
  37. }
  38. adapter.addAll(items);
  39. adapter.notifyDataSetChanged();
  40. Toast.makeText(getBaseContext(),"Success",Toast.LENGTH_SHORT).show();
  41. }
  42. catch (JSONException e)
  43. {
  44. Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
  45. }
  46. }
  47. }, new Response.ErrorListener() {
  48. @Override
  49. public void onErrorResponse(VolleyError volleyError) {
  50.  
  51. }
  52. });
  53.  
  54. Volley.newRequestQueue(getBaseContext()).add(jsonRequest);
  55. }
  56. }
  57.  
  58. public class CustomAdapter extends ArrayAdapter<Entity> {
  59. private final Context context;
  60. private final Entity[] values;
  61.  
  62. public CustomAdapter(Context context,Entity[] values)
  63. {
  64. super(context,-1,values);
  65. this.context = context;
  66. this.values = values;
  67. }
  68.  
  69. @Override
  70. public View getView(int position,View convertView,ViewGroup parent)
  71. {
  72. LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  73. View rowView = inflater.inflate(R.layout.list_row,parent,false);
  74. TextView id_text = (TextView)rowView.findViewById(R.id.row_id);
  75. TextView name_text = (TextView)rowView.findViewById(R.id.row_name);
  76. TextView url_text = (TextView)rowView.findViewById(R.id.row_url);
  77. id_text.setText(values[position].getId());
  78. name_text.setText(values[position].getName());
  79. url_text.setText(values[position].getUrl());
  80. return rowView;
  81. }
  82. }
  83.  
  84. 01-22 04:45:56.298 1492-1492/? W/EGL_genymotion: eglSurfaceAttrib not implemented
  85. 01-22 04:45:56.354 477-492/? I/ActivityManager: Displayed com.example.newfeeds.newfeeds/.VolleyActivity: +110ms
  86. 01-22 04:45:57.070 1492-1492/? D/AndroidRuntime: Shutting down VM
  87. 01-22 04:45:57.070 1492-1492/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa6219908)
  88. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: FATAL EXCEPTION: main
  89. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: java.lang.UnsupportedOperationException
  90. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at java.util.AbstractList.add(AbstractList.java:404)
  91. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at java.util.AbstractList.add(AbstractList.java:425)
  92. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at java.util.AbstractCollection.addAll(AbstractCollection.java:76)
  93. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at android.widget.ArrayAdapter.addAll(ArrayAdapter.java:195)
  94. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at com.example.newfeeds.newfeeds.VolleyActivity$2.onResponse(VolleyActivity.java:66)
  95. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at com.example.newfeeds.newfeeds.VolleyActivity$2.onResponse(VolleyActivity.java:51)
  96. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65)
  97. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
  98. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:725)
  99. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
  100. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
  101. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5041)
  102. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
  103. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
  104. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  105. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  106. 01-22 04:45:57.074 1492-1492/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
  107. 01-22 04:45:57.074 477-698/? W/ActivityManager: Force finishing activity com.example.newfeeds.newfeeds/.VolleyActivity
  108. 01-22 04:45:57.150 477-698/? D/dalvikvm: GC_FOR_ALLOC freed 129K, 29% free 9794K/13620K, paused 10ms, total 10ms
  109. 01-22 04:45:57.654 477-490/? W/ActivityManager: Activity pause timeout for ActivityRecord{533353cc u0 com.example.newfeeds.newfeeds/.VolleyActivity}
  110. 01-22 04:46:07.154 477-490/? W/ActivityManager: Launch timeout has expired, giving up wake lock!
  111. 01-22 04:46:07.654 477-490/? W/ActivityManager: Activity idle timeout for ActivityRecord{53441ff4 u0 com.example.newfeeds.newfeeds/.MainActivity}
  112. 01-22 04:46:20.714 56-56/? D/Genyd: Received Set Clipboard
  113. 01-22 04:46:20.714 56-56/? D/Genymotion: Received Set Clipboard
  114. 01-22 04:47:00.034 477-480/? D/dalvikvm: GC_CONCURRENT freed 1670K, 28% free 9848K/13620K, paused 1ms+2ms, total 25ms
  115. 01-22 04:47:15.470 56-56/? D/Genyd: Received Set Clipboard
  116. 01-22 04:47:15.470 56-56/? D/Genymotion: Received Set Clipboard
  117.  
  118. public class CustomAdapter extends ArrayAdapter<Entity> {
  119. private final Context context;
  120. private final ArrayList<Entity> values;
  121.  
  122. public CustomAdapter(Context context,ArrayList<Entity> values)
  123. {
  124. super(context,-1,values);
  125. this.context = context;
  126. this.values = values;
  127. }
  128.  
  129. @Override
  130. public View getView(int position,View convertView,ViewGroup parent)
  131. {
  132. LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  133. View rowView = inflater.inflate(R.layout.list_row,parent,false);
  134. TextView id_text = (TextView)rowView.findViewById(R.id.row_id);
  135. TextView name_text = (TextView)rowView.findViewById(R.id.row_name);
  136. TextView url_text = (TextView)rowView.findViewById(R.id.row_url);
  137. id_text.setText(values.get(position).getId());
  138. name_text.setText(values.get(position).getName());
  139. url_text.setText(values.get(position).getUrl());
  140. return rowView;
  141. }
  142. }
  143.  
  144. 01-22 05:09:54.770 1895-1895/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa6219908)
  145. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: FATAL EXCEPTION: main
  146. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: android.content.res.Resources$NotFoundException: String resource ID #0x1
  147. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.content.res.Resources.getText(Resources.java:230)
  148. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.TextView.setText(TextView.java:3769)
  149. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at com.example.newfeeds.newfeeds.CustomAdapter.getView(CustomAdapter.java:36)
  150. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.AbsListView.obtainView(AbsListView.java:2159)
  151. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.ListView.makeAndAddView(ListView.java:1831)
  152. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.ListView.fillDown(ListView.java:674)
  153. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.ListView.fillFromTop(ListView.java:735)
  154. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.ListView.layoutChildren(ListView.java:1638)
  155. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.AbsListView.onLayout(AbsListView.java:1994)
  156. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.View.layout(View.java:14008)
  157. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4373)
  158. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
  159. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
  160. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  161. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.View.layout(View.java:14008)
  162. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4373)
  163. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  164. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.View.layout(View.java:14008)
  165. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4373)
  166. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
  167. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
  168. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  169. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.View.layout(View.java:14008)
  170. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4373)
  171. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  172. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.View.layout(View.java:14008)
  173. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4373)
  174. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
  175. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
  176. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
  177. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
  178. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
  179. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:562)
  180. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:532)
  181. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
  182. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:725)
  183. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:92)
  184. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
  185. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5041)
  186. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
  187. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
  188. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  189. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  190. 01-22 05:09:54.774 1895-1895/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
  191. 01-22 05:09:54.778 477-489/? W/ActivityManager: Force finishing activity com.example.newfeeds.newfeeds/.VolleyActivity
  192. 01-22 05:09:54.894 477-489/? D/dalvikvm: GC_FOR_ALLOC freed 179K, 33% free 9817K/14460K, paused 15ms, total 15ms
  193. 01-22 05:09:55.398 477-490/? W/ActivityManager: Activity pause timeout for ActivityRecord{5334f1a0 u0 com.example.newfeeds.newfeeds/.VolleyActivity}
  194.  
  195. private final Context context;
  196. private final ArrayList<Entity> values;
  197.  
  198. public CustomAdapter(Context context,ArrayList<Entity> values;
  199. {
  200. super(context,-1,values);
  201. this.context = context;
  202. this.values = values;
  203. }
  204.  
  205. values.addAll(items);
  206.  
  207. adapter.notifyDataSetChanged();
  208.  
  209. public class Entity {
  210.  
  211. private String id;
  212. private String name;
  213. private String url;
  214.  
  215. public String getId() {
  216. return id;
  217. }
  218. public void setId(String id) {
  219. this.id = id;
  220. }
  221. public String getName() {
  222. return name;
  223. }
  224. public void setName(String name) {
  225. this.name = name;
  226. }
  227. public String getUrl() {
  228. return url;
  229. }
  230. public void setUrl(String url) {
  231. this.url = url;
  232. }
  233. }
  234.  
  235. public class ListVewTestThreeActivity extends AppCompatActivity {
  236.  
  237. private ListView listView;
  238. private ArrayList<Entity> entities;
  239. private MyAdapter myAdapter;
  240.  
  241. @Override
  242. protected void onCreate(Bundle savedInstanceState) {
  243. super.onCreate(savedInstanceState);
  244. setContentView(R.layout.activity_list_vew_test_three);
  245. Toolbar toolbar = (Toolbar) findViewById(R.id.my_custom_toolbar);
  246. setSupportActionBar(toolbar);
  247.  
  248. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  249.  
  250. initializeUI();
  251. }
  252.  
  253. private void initializeUI() {
  254. listView = (ListView) findViewById(R.id.ListVewTestThreeActivity_listView);
  255. entities = new ArrayList<>();
  256. myAdapter = new MyAdapter(getApplicationContext(), R.layout.simple_list_item_1, entities);
  257. listView.setAdapter(myAdapter);
  258.  
  259. new DownloadJSON().execute();
  260. }
  261.  
  262. private class DownloadJSON extends AsyncTask<Void, Void, Void> {
  263.  
  264. private ArrayList<Entity> tempEntities;
  265.  
  266. @Override
  267. protected void onPreExecute() {
  268. super.onPreExecute();
  269. tempEntities = new ArrayList<>();
  270. }
  271.  
  272. @Override
  273. protected Void doInBackground(Void... params) {
  274.  
  275. try {
  276.  
  277. URL url = new URL("http://api.androidhive.info/feed/feed.json");
  278. HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  279. httpURLConnection.connect();
  280.  
  281. String result = IOUtils.toString(httpURLConnection.getInputStream());
  282. System.out.println("" + result);
  283.  
  284. JSONObject jsonObject = new JSONObject(result);
  285. JSONArray jsonArray = jsonObject.getJSONArray("feed");
  286.  
  287. for (int i = 0; i < jsonArray.length(); i++) {
  288. Entity entity = new Entity();
  289. entity.setId(jsonArray.getJSONObject(i).getString("id"));
  290. entity.setName(jsonArray.getJSONObject(i).getString("name"));
  291. entity.setUrl(jsonArray.getJSONObject(i).getString("image"));
  292. System.out.println(""+entity.getName());
  293. tempEntities.add(entity);
  294. }
  295. } catch (Exception e) {
  296. e.printStackTrace();
  297. }
  298. return null;
  299. }
  300.  
  301. @Override
  302. protected void onPostExecute(Void aVoid) {
  303. super.onPostExecute(aVoid);
  304.  
  305. if (tempEntities != null) {
  306. entities.addAll(tempEntities);
  307. System.out.println("Size: "+entities.size());
  308. myAdapter.notifyDataSetChanged();
  309. }
  310.  
  311. }
  312. }
  313.  
  314.  
  315. private class MyAdapter extends ArrayAdapter {
  316.  
  317. private ArrayList<Entity> a_productInfos;
  318. private Context a_context;
  319. private LayoutInflater a_layoutInflater;
  320.  
  321. public MyAdapter(Context context, int resource, ArrayList<Entity> a_productInfos) {
  322. super(context, resource, a_productInfos);
  323. this.a_productInfos = a_productInfos;
  324. this.a_context = context;
  325. a_layoutInflater = LayoutInflater.from(this.a_context);
  326. }
  327.  
  328.  
  329. @Override
  330. public View getView(int position, View convertView, ViewGroup parent) {
  331. View row = convertView;
  332. ViewHolder holder = null;
  333. if (row == null) {
  334. row = a_layoutInflater.inflate(R.layout.single_item_listview_test_three, parent, false);
  335. holder = new ViewHolder();
  336. holder.id = (TextView) row.findViewById(R.id.ListVewTestThreeActivity_id_textView);
  337. holder.name = (TextView) row.findViewById(R.id.ListVewTestThreeActivity_name_textView);
  338. holder.url = (TextView) row.findViewById(R.id.ListVewTestThreeActivity_url_textView);
  339. row.setTag(holder);
  340. } else {
  341. holder = (ViewHolder) row.getTag();
  342. }
  343.  
  344. final Entity productInfo = a_productInfos.get(position);
  345. holder.id.setText("" + productInfo.getId());
  346. holder.name.setText("" + productInfo.getName());
  347. holder.url.setText("" + productInfo.getUrl());
  348. return row;
  349. }
  350.  
  351. class ViewHolder {
  352. TextView id;
  353. TextView name;
  354. TextView url;
  355. }
  356.  
  357. @Override
  358. public int getCount() {
  359. return super.getCount();
  360. }
  361. }
  362.  
  363. public class Entity {
  364.  
  365. private String id;
  366. private String name;
  367. private String url;
  368.  
  369. public String getId() {
  370. return id;
  371. }
  372.  
  373. public void setId(String id) {
  374. this.id = id;
  375. }
  376.  
  377. public String getName() {
  378. return name;
  379. }
  380.  
  381. public void setName(String name) {
  382. this.name = name;
  383. }
  384.  
  385. public String getUrl() {
  386. return url;
  387. }
  388.  
  389. public void setUrl(String url) {
  390. this.url = url;
  391. }
  392. }
  393. }
  394.  
  395. id_text.setText(String.valueOf(values[position].getId()))
  396.  
  397. public class VolleyActivity extends Activity{
  398. private int lastSawFirstListItem;
  399. private int itemLoadedOn;
  400. private ArrayAdapter adapter;
  401. private List<Entity> items;
  402. @Override
  403. protected void onCreate(Bundle savedInstanceState) {
  404. super.onCreate(savedInstanceState);
  405. setContentView(R.layout.volley_main);
  406.  
  407. Button getBtn = (Button)findViewById(R.id.btn_get_request);
  408. getBtn.setOnClickListener(new View.OnClickListener() {
  409. @Override
  410. public void onClick(View v) {
  411.  
  412. }
  413. });
  414. items = new ArrayList<Entity>();
  415. ListView listView = (ListView)findViewById(R.id.volleyListView);
  416. adapter = new CustomAdapter(this, items);
  417. listView.setAdapter(adapter);
  418. String url = "http://api.androidhive.info/feed/feed.json";
  419.  
  420. JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
  421. @Override
  422. public void onResponse(JSONObject jsonObject) {
  423. List<Entity> items = new ArrayList<Entity>();
  424. try{
  425. JSONArray jsonArray = jsonObject.getJSONArray("feed");
  426. for(int i=0;i<jsonArray.length();i++)
  427. {
  428. JSONObject item = jsonArray.getJSONObject(i);
  429. Entity en = new Entity();
  430. en.setId(item.getInt("id"));
  431. en.setName(item.getString("name"));
  432. en.setUrl(item.getString("url"));
  433. items.add(en);
  434. }
  435. adapter.addAll(items);
  436. adapter.notifyDataSetChanged();
  437. Toast.makeText(getBaseContext(),"Success",Toast.LENGTH_SHORT).show();
  438. }
  439. catch (JSONException e)
  440. {
  441. Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
  442. }
  443. }
  444. }, new Response.ErrorListener() {
  445. @Override
  446. public void onErrorResponse(VolleyError volleyError) {
  447.  
  448. }
  449. });
  450.  
  451. Volley.newRequestQueue(getBaseContext()).add(jsonRequest);
  452. }
  453. }
  454.  
  455. public class CustomAdapter extends ArrayAdapter<Entity> {
  456. private final Context context;
  457. private List<Entity> values;
  458.  
  459. public CustomAdapter(Context context,List<Entity> values){
  460. super(context,-1,values);
  461. this.context = context;
  462. this.values = values;
  463. }
  464.  
  465. @Override
  466. public View getView(int position,View convertView,ViewGroup parent)
  467. {
  468. LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  469. View rowView = inflater.inflate(R.layout.list_row,parent,false);
  470. TextView id_text = (TextView)rowView.findViewById(R.id.row_id);
  471. TextView name_text = (TextView)rowView.findViewById(R.id.row_name);
  472. TextView url_text = (TextView)rowView.findViewById(R.id.row_url);
  473. id_text.setText(String.valueOf(values.get(position).getId()));
  474. name_text.setText(values.get(position).getName());
  475. url_text.setText(values.get(position).getUrl());
  476. return rowView;
  477. }
  478. }
  479.  
  480. String.valueOf(values.get(position).getId())
Add Comment
Please, Sign In to add comment