help for listview?

by Hitendrasinh Gohil » Thu, 19 May 2011 04:51:00 GMT


Sponsored Links
 ere is my class for listview. it has one edittext for
searching.whenever search button clicked data ll be loaded to
listview.but it is not happening.list is not populating with data.

can anyone suggest me what is the wrong with this code?



package com.musix.main;
import com.musix.model.JsonParser;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class TrackActivity extends SearchComponent
{
private ListView listview;
private OrderAdapter orderAdapter;
public void onCreate(Bundle instance)
{
super.onCreate(instance);

ViewGroup viewgroup=(ViewGroup)findViewById(R.id.FrameLayout01);

ViewGroup.inflate(getApplicationContext(),R.layout.track,viewgroup);
listview=(ListView)findViewById(R.id.tracklist);
orderAdapter=new OrderAdapter(this);
listview.setAdapter(orderAdapter);
}
private class OrderAdapter extends BaseAdapter
{
private LayoutInflater mInflater;

public OrderAdapter(Context context)
{
mInflater = LayoutInflater.from(context);
}

public View getView(int position, View convertView, ViewGroup
parent)
{
ViewHolder holder;

// Here if condition check view is null or not. If view
is null
then it will inflate
// album row and initialize it, otherwise it will get
tag and
assign it to holder.

if (convertView == null)
{
convertView =
mInflater.inflate(R.layout.trackrow, null);
holder = new ViewHolder();

holder.trackname = (TextView)
convertView.findViewById(R.id.trackname);
holder.trackalbum = (TextView)
convertView.findViewById(R.id.albumartistname);

convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}


holder.trackname.setText(JsonParser.TRACKDETAILS.get(position).getTracktitle());

holder.trackalbum.setText(JsonParser.TRACKDETAILS.get(position).getArtistname());

convertView.setOnClickListener(new
OnItemClickListener(position));
return convertView;
}

public class ViewHolder
{
public TextView trackname, trackalbum;
@SuppressWarnings("unused")
public ImageView imgAlbumArt;
}

public int getCount(){return JsonParser.NEWSLIST.size();}
public Object getItem(int position){return position;}
public long getItemId(int position){return position;}



Re: help for listview?

by TreKing » Thu, 19 May 2011 05:25:41 GMT


 On Wed, May 18, 2011 at 3:50 PM, Hitendrasinh Gohil <





You import android.util.Log but don't have a single log statement.

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 


Sponsored Links


Re: help for listview?

by Justin Anderson » Thu, 19 May 2011 05:30:11 GMT


 Have you tried stepping through the code in the Eclipse debugger? What
happens when you do?

Thanks,
Justin Anderson
MagouyaWare Developer
 http://sites.google.com/site/magouyaware 







-- 



Re: help for listview?

by Hitendrasinh Gohil » Thu, 19 May 2011 12:03:19 GMT


 when activity loads frist time getview method is called but when i clicked
on search  data   orderAdapter.
notifyDataSetChanged();
orderAdapter.notifyDataSetInvalidated();,these methods called but not
reflcted in list.


then i have tried starting same activity and finish it on click event,in
that case oncreate method is called but getview is not called.


have u anyguess?


i simply want to load data on listview when search event is called?this
search is within three activities.



-- 
Regards,
Hitendrasinh Gohil

-- 



Re: help for listview?

by gyanu maharjan » Thu, 19 May 2011 12:45:49 GMT


 case R.id.btnsearch:
                       List<NameValuePair> nameValues=new
ArrayList<NameValuePair>();
                       nameValues.add(new
BasicNameValuePair("t",
edittext.getText().toString()));
                       nameValues.add(new BasicNameValuePair("p","1"));
                       String data=new
HttpRetriever().getSearchdata(UrlConstants.BASEURL
+UrlConstants.SEARCH, nameValues);
                       new JsonParser().parseSearchTrackValue(data);
                       break;

you want to set list view when search button is clicked,i think you should
set setContentView(R.id.list) belonging to listView and set suitable Adapter
for it.


On Thu, May 19, 2011 at 9:47 AM, Hitendrasinh Gohil <




-- 



Re: help for listview?

by Hitendrasinh Gohil » Thu, 19 May 2011 20:29:02 GMT


 hi,

whether i am setting layout before click event or after it doesnt
affect.because we can notify list by calling its adapter
method.(notifydatasetchanged()).

can can anyone please have a look at this ,and suggest where the problem is!

-- 



Re: help for listview?

by Francisco Dalla Rosa soares » Thu, 19 May 2011 20:53:27 GMT


 1. your ViewHolder class isn't static. if It's not it will always be null
for the next call. (this is not the reason for your problem though)

2. your getItem should be returning an object but it's returning just the
position

3. notifyDataSetInvalidated() means that the data inside the adapter is
no longer valid. This will cause ListView to stop populating (Romain Guy)

4.shouldn't you be calling notifyDatasetChanged() after that parse call?
2011/5/19 Hitendrasinh Gohil <hitendra.virtuei...@gmail.com>


-- 



Re: help for listview?

by Hitendrasinh Gohil » Thu, 19 May 2011 20:58:53 GMT


 hi,

i have just called only notifyDatasetChanged(),but didnt work then i have
added   notifyDataSetInvalidated().


-- 
Regards,
Hitendrasinh Gohil

-- 



Other Threads

1. Form checking?

My app has a form in it (for the user to enter info that will
eventually be sent off to a web API) and I need to do some form field
checking locally. Pretty standard stuff - basically that there are no
blank fields and that they've entered a valid email address.

What's the best way to do this?

Basically I'm wondering whether I can attach Javascript to TextViews,
or whether I'm best off using a WebView and doing the whole thing in
HTML.

Any hints appreciated...

cheers
Anna

--~--~---------~--~----~------------~-------~--~----~

2. Can't create Hello Android Project

I'm not able to create a new project - When I get to the New Android
Project screen there's a warning at the top that "Package name must be
specified." and after filling in the page as shown in the example, the
warning stays and won't allow me to click next

--~--~---------~--~----~------------~-------~--~----~

3. call WebService

4. Device for the future with android apps

5. Using the Log class

6. List Field Problem while porting from 0.5 to 0.9 and to 1.0 SDK

7. OpenStreetMap MapView for Android