Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
ZTE MF283U 4G Unlocked Router (Used)
ayanthamaxi
Updated:
Sunday at 8:26 PM
ලංකාවේ හොඳම උපකාරක පන්ති සහ ගුරුවරුන් එකම තැනකින් - TopTuition.lk
dulithapathum
Updated:
Saturday at 8:07 AM
Colombo
RidhMathraa ’26 🎶✨
Tmadhusanka
Updated:
Wednesday at 11:58 PM
Ad icon
Colombo
PXN V10 Pro Direct Drive Racing Wheel (Under Warranty)
Abdur Rahman
Updated:
Wednesday at 10:23 PM
Ad icon
USDT ණය සේවාව - USDT Loan Service
පුරවැසියා
Updated:
Wednesday at 4:54 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Android, JAVA ListView Help
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="sachi911" data-source="post: 20128510" data-attributes="member: 265113"><p style="text-align: center"><span style="font-size: 12px">I have a ListView on my app that extends the BaseAdapter. When i debug it via usb debugging, first time the ListView works. But when i run the app again or go back to the activity that contains the ListView, it doesnt populate. I just get a blank activity.</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px">Here is my Adapter</span></p> <p style="text-align: center"></p> <p style="text-align: center">[CODE]public class CustomListAdapter extends BaseAdapter {</p> <p style="text-align: center"></p> <p style="text-align: center"> private Activity activity;</p> <p style="text-align: center"> private LayoutInflater inflater;</p> <p style="text-align: center"> private List<Guide> guideItems;</p> <p style="text-align: center"></p> <p style="text-align: center"> public CustomListAdapter(Activity activity, List<Guide> guideItems) {</p> <p style="text-align: center"> this.activity = activity;</p> <p style="text-align: center"> this.guideItems = guideItems;</p> <p style="text-align: center"> }</p> <p style="text-align: center"></p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public int getCount() {</p> <p style="text-align: center"> return guideItems.size();</p> <p style="text-align: center"> }</p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public Object getItem(int location) {</p> <p style="text-align: center"> return guideItems.get(location);</p> <p style="text-align: center"> }</p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public long getItemId(int position) {</p> <p style="text-align: center"> return position;</p> <p style="text-align: center"> }</p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public View getView(int position, View convertView, ViewGroup parent) {</p> <p style="text-align: center"></p> <p style="text-align: center"> // if (inflater == null)</p> <p style="text-align: center"> inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);</p> <p style="text-align: center"> // if (convertView == null)</p> <p style="text-align: center"> // convertView = inflater.inflate(R.layout.customrow, null);</p> <p style="text-align: center"> convertView = inflater.inflate(R.layout.customrow, parent, false);</p> <p style="text-align: center"></p> <p style="text-align: center"> //if (imageLoader == null)</p> <p style="text-align: center"> // imageLoader = AppController.getInstance().getImageLoader();</p> <p style="text-align: center"> // NetworkImageView thumbNail = (NetworkImageView) convertView</p> <p style="text-align: center"> // .findViewById(R.id.thumbnail);</p> <p style="text-align: center"></p> <p style="text-align: center"> TextView ngno = (TextView) convertView.findViewById(R.id.txt_ListNgno);</p> <p style="text-align: center"> TextView name = (TextView) convertView.findViewById(R.id.txt_ListName);</p> <p style="text-align: center"> TextView email = (TextView) convertView.findViewById(R.id.txt_ListEmail);</p> <p style="text-align: center"></p> <p style="text-align: center"> // getting guide data for the row</p> <p style="text-align: center"> Guide g = guideItems.get(position);</p> <p style="text-align: center"> //thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader);</p> <p style="text-align: center"> ngno.setText(g.getNgno());</p> <p style="text-align: center"> name.setText(g.getName());</p> <p style="text-align: center"> email.setText(g.getEmail());</p> <p style="text-align: center"></p> <p style="text-align: center"> return convertView;</p> <p style="text-align: center"> }</p> <p style="text-align: center">}[/CODE]</p> <p style="text-align: center"></p> <p style="text-align: center"></p> <p style="text-align: center"><span style="font-size: 12px">This is my ListView Activity.</span></p> <p style="text-align: center"></p> <p style="text-align: center"></p> <p style="text-align: center">[CODE]public class ViewGuidesActivity extends AppCompatActivity {</p> <p style="text-align: center"></p> <p style="text-align: center"> private static final String TAG = ViewGuidesActivity.class.getSimpleName();</p> <p style="text-align: center"> private ProgressDialog pDialog;</p> <p style="text-align: center"> private List<Guide> guideList = new ArrayList<Guide>();</p> <p style="text-align: center"> private ListView listView;</p> <p style="text-align: center"> private CustomListAdapter adapter;</p> <p style="text-align: center"></p> <p style="text-align: center"></p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> protected void onCreate(Bundle savedInstanceState) {</p> <p style="text-align: center"> super.onCreate(savedInstanceState);</p> <p style="text-align: center"> setContentView(R.layout.activity_view_guides);</p> <p style="text-align: center"></p> <p style="text-align: center"> Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);</p> <p style="text-align: center"> setSupportActionBar(toolbar);</p> <p style="text-align: center"> this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);</p> <p style="text-align: center"></p> <p style="text-align: center"> listView = (ListView) findViewById(R.id.list);</p> <p style="text-align: center"> adapter = new CustomListAdapter(this, guideList);</p> <p style="text-align: center"> listView.setAdapter(adapter);</p> <p style="text-align: center"></p> <p style="text-align: center"> pDialog = new ProgressDialog(this);</p> <p style="text-align: center"> // Showing progress dialog before making http request</p> <p style="text-align: center"> pDialog.setMessage("Loading...");</p> <p style="text-align: center"> pDialog.show();</p> <p style="text-align: center"></p> <p style="text-align: center"> // Creating volley request obj</p> <p style="text-align: center"> JsonArrayRequest movieReq = new JsonArrayRequest(AppConfig.URL_GET_GUIDE_LIST,</p> <p style="text-align: center"> new Response.Listener<JSONArray>() {</p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public void onResponse(JSONArray response) {</p> <p style="text-align: center"> Log.d(TAG, response.toString());</p> <p style="text-align: center"> hidePDialog();</p> <p style="text-align: center"></p> <p style="text-align: center"> // Parsing json</p> <p style="text-align: center"> for (int i = 0; i < response.length(); i++) {</p> <p style="text-align: center"> try {</p> <p style="text-align: center"></p> <p style="text-align: center"> JSONObject obj = response.getJSONObject(i);</p> <p style="text-align: center"> Guide guide = new Guide();</p> <p style="text-align: center"> guide.setNgno(obj.getString("ngno"));</p> <p style="text-align: center"> guide.setEmail(obj.getString("email"));</p> <p style="text-align: center"> guide.setName(obj.getString("name"));</p> <p style="text-align: center"></p> <p style="text-align: center"></p> <p style="text-align: center"> // adding guide to guide array</p> <p style="text-align: center"> guideList.add(guide);</p> <p style="text-align: center"></p> <p style="text-align: center"> } catch (JSONException e) {</p> <p style="text-align: center"> e.printStackTrace();</p> <p style="text-align: center"> }</p> <p style="text-align: center"></p> <p style="text-align: center"> }</p> <p style="text-align: center"></p> <p style="text-align: center"> // notifying list adapter about data changes </p> <p style="text-align: center"> adapter.notifyDataSetChanged();</p> <p style="text-align: center"> }</p> <p style="text-align: center"> }, new Response.ErrorListener() {</p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public void onErrorResponse(VolleyError error) {</p> <p style="text-align: center"> Log.d(TAG, error.toString());</p> <p style="text-align: center"> VolleyLog.d(TAG, "Error: " + error.getMessage());</p> <p style="text-align: center"> hidePDialog();</p> <p style="text-align: center"></p> <p style="text-align: center"> }</p> <p style="text-align: center"> });</p> <p style="text-align: center"></p> <p style="text-align: center"> // Adding request to request queue</p> <p style="text-align: center"> AppController.getInstance().addToRequestQueue(movieReq);</p> <p style="text-align: center"></p> <p style="text-align: center"> listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {</p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {</p> <p style="text-align: center"> Guide newGuide = guideList.get(position);</p> <p style="text-align: center"> String email = newGuide.getEmail();</p> <p style="text-align: center"> String ngno = newGuide.getNgno();</p> <p style="text-align: center"> //System.out.println(email);</p> <p style="text-align: center"></p> <p style="text-align: center"> Intent i = new Intent(getApplicationContext(), GuideDetails.class);</p> <p style="text-align: center"> i.putExtra("email", email);</p> <p style="text-align: center"> i.putExtra("ngno", ngno);</p> <p style="text-align: center"> startActivity(i);</p> <p style="text-align: center"> }</p> <p style="text-align: center"> });</p> <p style="text-align: center"></p> <p style="text-align: center"> }</p> <p style="text-align: center"></p> <p style="text-align: center"> @Override</p> <p style="text-align: center"> public void onDestroy() {</p> <p style="text-align: center"> super.onDestroy();</p> <p style="text-align: center"> hidePDialog();</p> <p style="text-align: center"> }</p> <p style="text-align: center"></p> <p style="text-align: center"> private void hidePDialog() {</p> <p style="text-align: center"> if (pDialog != null) {</p> <p style="text-align: center"> pDialog.dismiss();</p> <p style="text-align: center"> pDialog = null;</p> <p style="text-align: center"> }</p> <p style="text-align: center"> }</p> <p style="text-align: center"> </p> <p style="text-align: center">}[/CODE]</p> <p style="text-align: center"></p> <p style="text-align: center"></p> <p style="text-align: center"><span style="font-size: 12px">Any ideas why this happens? <img src="/styles/default/xenforo/smilies/default/sad.gif" class="smilie" loading="lazy" alt=":(" title="Sad :(" data-shortname=":(" /> only way to fix this is to clear my application cache thought settings and run the app again. then it works the first time and same story happens. Do i have to purge the adapter memory or something when i leave the activity? </span></p></blockquote><p></p>
[QUOTE="sachi911, post: 20128510, member: 265113"] [CENTER][SIZE="3"]I have a ListView on my app that extends the BaseAdapter. When i debug it via usb debugging, first time the ListView works. But when i run the app again or go back to the activity that contains the ListView, it doesnt populate. I just get a blank activity. Here is my Adapter[/SIZE] [CODE]public class CustomListAdapter extends BaseAdapter { private Activity activity; private LayoutInflater inflater; private List<Guide> guideItems; public CustomListAdapter(Activity activity, List<Guide> guideItems) { this.activity = activity; this.guideItems = guideItems; } @Override public int getCount() { return guideItems.size(); } @Override public Object getItem(int location) { return guideItems.get(location); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // if (inflater == null) inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // if (convertView == null) // convertView = inflater.inflate(R.layout.customrow, null); convertView = inflater.inflate(R.layout.customrow, parent, false); //if (imageLoader == null) // imageLoader = AppController.getInstance().getImageLoader(); // NetworkImageView thumbNail = (NetworkImageView) convertView // .findViewById(R.id.thumbnail); TextView ngno = (TextView) convertView.findViewById(R.id.txt_ListNgno); TextView name = (TextView) convertView.findViewById(R.id.txt_ListName); TextView email = (TextView) convertView.findViewById(R.id.txt_ListEmail); // getting guide data for the row Guide g = guideItems.get(position); //thumbNail.setImageUrl(m.getThumbnailUrl(), imageLoader); ngno.setText(g.getNgno()); name.setText(g.getName()); email.setText(g.getEmail()); return convertView; } }[/CODE] [SIZE="3"]This is my ListView Activity.[/SIZE] [CODE]public class ViewGuidesActivity extends AppCompatActivity { private static final String TAG = ViewGuidesActivity.class.getSimpleName(); private ProgressDialog pDialog; private List<Guide> guideList = new ArrayList<Guide>(); private ListView listView; private CustomListAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view_guides); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); this.getSupportActionBar().setDisplayHomeAsUpEnabled(true); listView = (ListView) findViewById(R.id.list); adapter = new CustomListAdapter(this, guideList); listView.setAdapter(adapter); pDialog = new ProgressDialog(this); // Showing progress dialog before making http request pDialog.setMessage("Loading..."); pDialog.show(); // Creating volley request obj JsonArrayRequest movieReq = new JsonArrayRequest(AppConfig.URL_GET_GUIDE_LIST, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { Log.d(TAG, response.toString()); hidePDialog(); // Parsing json for (int i = 0; i < response.length(); i++) { try { JSONObject obj = response.getJSONObject(i); Guide guide = new Guide(); guide.setNgno(obj.getString("ngno")); guide.setEmail(obj.getString("email")); guide.setName(obj.getString("name")); // adding guide to guide array guideList.add(guide); } catch (JSONException e) { e.printStackTrace(); } } // notifying list adapter about data changes adapter.notifyDataSetChanged(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, error.toString()); VolleyLog.d(TAG, "Error: " + error.getMessage()); hidePDialog(); } }); // Adding request to request queue AppController.getInstance().addToRequestQueue(movieReq); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { Guide newGuide = guideList.get(position); String email = newGuide.getEmail(); String ngno = newGuide.getNgno(); //System.out.println(email); Intent i = new Intent(getApplicationContext(), GuideDetails.class); i.putExtra("email", email); i.putExtra("ngno", ngno); startActivity(i); } }); } @Override public void onDestroy() { super.onDestroy(); hidePDialog(); } private void hidePDialog() { if (pDialog != null) { pDialog.dismiss(); pDialog = null; } } }[/CODE] [SIZE="3"]Any ideas why this happens? :( only way to fix this is to clear my application cache thought settings and run the app again. then it works the first time and same story happens. Do i have to purge the adapter memory or something when i leave the activity? [/SIZE][/CENTER] [/QUOTE]
Insert quotes…
Verification
Winadiyakata thappara keeyak tibeda?
Post reply
Top
Bottom