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. Horizontal Zoomslider widget possible

Is it possible to change the ZoomSlider widget to a horizontal style?

thanks in advance

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

2. Response to alert dialog button programatically

I have an alert dialog like this :

********************************************
new AlertDialog.Builder(mContext)
.setTitle("Testing")
.setMessage("Buy this thing?")
.setPositiveButton(R.string.yes, yesListener)
.setNegativeButton(R.string.no, noListener)
.show();
********************************************

If we pressed the positive button, the program will run the
yesListener and run the noListener if we pressed the negative button.

What i want is, if the program met certain condition, the alert dialog
will show, and program automatically pressed the positive / negative
button.

I don't want to access the method directly, because i want the dialog
to be shown first... (it's done as if human pressed the button).

Is it possible?

Thanks,
sasuke
--~--~---------~--~----~------------~-------~--~----~

3. New activity / extends

4. Thoughts on $10,000 competition "iPhone apps battling Android apps" please

5. How to access custom Contactfields

6. How can I achieve to change the other theme in run time and set spinner selector location

7. Socket I/O in Android