getView from overloaded ArrayAdapter is not beeing called from AsyncTask / onPostExecute - java

Hi its my first post here nad my first a little bit more advanced app for my Android phone... I know that this subject was mentioned here, google knows many examples, however they are not exacty what im looking form ;(
I admit I'm a n00000b... in terms of Android coding... I started... ust few days ago, please forgive me :)
The problem is that my listview element is not beeing populated. App compiles and runs without errors, BUT it doesnt lunch getView. From what i have read on the web... I need this to display my beloved listview with its content...
Please help :)
package com.test.stackParser;
public class StackParserActivity extends Activity {
/** Called when the activity is first created. */
private ProgressDialog pd;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//final TextView tv = (TextView) findViewById(R.id.textView1);
//tv.setMovementMethod(new ScrollingMovementMethod());
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(myListener);
}
private OnClickListener myListener = new OnClickListener() {
public void onClick(View v) {
pd = ProgressDialog.show(StackParserActivity.this, "Working...", "request to server", true, false);
new ParseSite().execute("http://multikino.pl/pl/repertuar/warszawa-ursynow/2011-09-02/");
}
};
private class ParseSite extends AsyncTask<String, Void, List<String>> {
protected List<String> doInBackground(String... arg) {
List<String> output = new ArrayList<String>();
try
{
HtmlHelper hh = new HtmlHelper(new URL(arg[0]));
List<TagNode> links = hh.getLinksByClass("title");
for (Iterator<TagNode> iterator = links.iterator(); iterator.hasNext();)
{
TagNode divElement = (TagNode) iterator.next();
output.add(divElement.getText().toString());
}
Log.d("dupa", "siteParsed");
}
catch(Exception e)
{
e.printStackTrace();
}
return output;
}
protected void onPostExecute(List<String> output) {
pd.dismiss();
Log.d("dupa", "postExecute");
ListView listview = (ListView) findViewById(R.id.listViewData);
//listview.setAdapter(new ArrayAdapter<String>(StackParserActivity.this, android.R.layout.simple_list_item_1 , output));
MyAdapter dupa = new MyAdapter(StackParserActivity.this, android.R.layout.simple_list_item_1, R.id.movieTitle, output);
dupa.notifyDataSetChanged();
listview.setAdapter(dupa);
dupa.notifyDataSetChanged();
}
}
private class MyAdapter extends ArrayAdapter<string> {
String[] tabObj;
public MyAdapter(Context context, int resource, int textViewResourceId, List<String> output) {
super(context, resource, textViewResourceId);
tabObj = output.toArray(new String[]{});
Log.d("dupa", tabObj[2].toString());
notifyDataSetChanged();
// TODO Auto-generated constructor stub
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.d("dupa", "!!!!getView");
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.row_layout,parent,false);
TextView tv = (TextView) row.findViewById(R.id.movieTitle);
tv.setText(tabObj[position]);
//Button buton1 = (Button) row.findViewById(R.id.buttonInfo);
//Button button2 = (Button) row.findViewById(R.id.buttonReserve);
return super.getView(position, convertView, parent);
}
};
}

Return row from getView method. Also remove the notifyDatasetChanged() from the MyAdapter constructor.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.d("dupa", "!!!!getView");
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.row_layout,parent,false);
TextView tv = (TextView) row.findViewById(R.id.movieTitle);
tv.setText(tabObj[position]);
//Button buton1 = (Button) row.findViewById(R.id.buttonInfo);
//Button button2 = (Button) row.findViewById(R.id.buttonReserve);
return row;
}
EDIT :
Try overriding getCount in adapter where you return the size() of tabObj

Since you set the adapter onPostExecute, there is no need to set notifyDataChanged in any of the places that you call it.
The reason that notifyDataChanged is used is to notify the adapter that has been set to a listview that the data have changed and you should update it. Hope this helps!

private class MyAdapter extends ArrayAdapter<string> {
String[] tabObj;
public MyAdapter(Context context, int resource, int textViewResourceId, List<String> output) {
super(context, resource, textViewResourceId);
tabObj = output.toArray(new String[]{});
When we are creating a custom arrayadapter we must be using either
public ArrayAdapter (Context context, int textViewResourceId, T[] objects)
public ArrayAdapter (Context context, int resource, int textViewResourceId, T[] objects)
public ArrayAdapter (Context context, int textViewResourceId, List<T> objects)
public ArrayAdapter (Context context, int resource, int textViewResourceId, List<T> objects)
if we are not using above mention adapter, we need to override getCount() method.
In your case,
super(context, resource, textViewResourceId,output);
will solve your problem.

Related

Array Adapter's "getView()" doesn't get called [duplicate]

Here is the code of the fragment in which I am setting a custom adapter to the list.
There no errors but the ListView is empty. I have implemented getCount() which returns right number of items in my ArrayList. I don't see ("Inside", "GetView") in the logcat
Fragment
public class ServiceCarListFragment extends Fragment {
private String url;
private ArrayList<CarDetail> carDetailList = new ArrayList<CarDetail>();
private CarListAdapter adapter;
private ListView mList;
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
url = getActivity().getIntent().getStringExtra("url");
new DownloadCarDetail().execute(url);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater.inflate(R.layout.fragment_service_car_list, container, false);
mList = (ListView) v.findViewById(R.id.list);
mList.setAdapter(adapter);
for (CarDetail car : carDetailList) {
// START LOADING IMAGES FOR EACH STUDENT
car.loadImage(adapter);
}
return v;
}
class DownloadCarDetail extends AsyncTask<String, String, ArrayList<CarDetail>> {
#Override
protected ArrayList<CarDetail> doInBackground(String... params) {
// TODO Auto-generated method stub
ArrayList<CarDetail> carDetailList = JsonParser.parseJson(params[0]);
return carDetailList;
}
#Override
protected void onPostExecute(ArrayList<CarDetail> carDetailList) {
// TODO Auto-generated method stub
ServiceCarListFragment.this.carDetailList = carDetailList;
Log.d("dccs", String.valueOf(ServiceCarListFragment.this.carDetailList.size()));
adapter = new CarListAdapter(getActivity(), ServiceCarListFragment.this.carDetailList);
Log.d("dccs", String.valueOf((adapter.getCount())));
}
}
}
CustomAdapter
public class CarListAdapter extends BaseAdapter {
private ArrayList<CarDetail> items = new ArrayList<CarDetail>();
private Context context;
public CarListAdapter(Context context, ArrayList<CarDetail> items) {
this.context = context;
this.items = items;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.d("Inside", "GetView");
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
ViewHolder holder = null;
CarDetail car = items.get(position);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.car_list_row, null);
holder = new ViewHolder();
holder.tvCarName = (TextView) convertView.findViewById(R.id.tvCarName);
holder.tvDailyPriceValue = (TextView) convertView.findViewById(R.id.tvWeeklyPriceValue);
holder.tvWeeklyPriceValue = (TextView) convertView.findViewById(R.id.tvWeeklyPriceValue);
holder.imgCar = (ImageView) convertView.findViewById(R.id.imgCar);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvCarName.setText(car.getCarName());
if (car.getImage() != null) {
holder.imgCar.setImageBitmap(car.getImage());
} else {
// MY DEFAULT IMAGE
holder.imgCar.setImageResource(R.drawable.ic_action_call);
}
return convertView;
}
static class ViewHolder {
TextView tvCarName;
TextView tvDailyPriceValue;
TextView tvWeeklyPriceValue;
ImageView imgCar;
}
}
The only reasons getView is not called are:
getCount returns 0.
you forget to call setAdapter on the ListView.
If the ListView's visibility (or its container's visibility) is GONE. Thanks to #TaynãBonaldo for the valuable input.
ListView is not attached to any viewport layout. That is, mListView = new ListView(...) is used without myLayout.addView(mListView).
In the onPostExcute, after you create a new instance of CarListAdapter I will suggest you to update the new instance to your ListView. Indeed you need to call again
mList.setAdapter(adapter);
Edit: setAdapter should be always called on the ui thread, to avoid unexpected behaviours
Edit2:
The same applies to RecyclerView. Make sure that
getItemCount is returning a value grater than 0 (usually the dataset size)
both setLayoutManager and setAdapter have to be called on the UI Thread
The visibility of the widget has to be set to VISIBLE
you must verify that the list has elements might have an error when adding items to your list .
To verify , use the method:
adapter.getCount();
I faced similar problem. Here is a simple work around to solve it:
In your onCreateView, you will have to wait before the view gets created. So change your lines from this:
mList = (ListView)v.findViewById(R.id.list);
mList.setAdapter(adapter);
CHANGE THE ABOVE TWO LINES INTO:
mList = (ListView)v.findViewById(R.id.list);
mList.post(new Runnable() {
public void run() {
mList.setAdapter(adapter);
}
});
Hope this will help others who would run into similar problem
You are missing the super class in the constructor. See my example below:
public AppDataAdapter(Activity a, int textViewResourceId, ArrayList<AppData> entries) {
super(a, textViewResourceId, entries);
this.entries = entries;
this.activity = a;
}
What you have been doing is
In your adapter
public CarListAdapter(Context context , ArrayList<CarDetail> items) {
this.context = context;
this.items = items;
}
in your Fragment
adapter = new CarListAdapter(getActivity(),ServiceCarListFragment.this.carDetailList);
I hope you will be using FragmentActivity
You need to call
adapter = new CarListAdapter(YOUR_ACTIVITY_CONTEXT, carDetailList);
where YOUR_ACTIVITY_CONTEXT will be your FragmentActivity
I had the same problem. And after trying all tips above my getView was still not being called. So I tried to remove the ScrollView that I used outside the ListView. Then the getView worked well. Just for add one more posibility. I Hope help someone.

Start chronometer on each row of Listview in android

I have list items on one list layout among items i have there is a chronometer that i need to start on each row ,other items come from database, but when activity launches Chronometer stays on 00:00. Please help me , i did many research some tell me that in can use adapter but i am not familiar with it, i don't know if there is not another way to do it without using adapter .
MainActivity .java:
private ArrayList<HashMap<String, String>> userList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myList = (ListView)findViewById(R.id.listView);
inflatedView =
getLayoutInflater().inflate(R.layout.payement_timing_list_adapter_view, null);
chronometer = (Chronometer)
inflatedView.findViewById(R.id.chronometer);
if (userList.size() != 0) {
//Set the User Array list in ListView
adapter = new SimpleAdapter(getApplicationContext(), userList, R.layout.payement_timing_list_adapter_view,
new String[]{"Driver_fullname", "plate_no", "parking_name"},
new int[]{R.id.drivername, R.id.plateno, R.id.pname});
myList.setAdapter(adapter);
}
myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
Log.d("My POSITION",""+position);
((Chronometer)inflatedView.findViewById(R.id.chronometer)).myList.
(position).start();
chronometer.start();
}
});
You will need to use a custom adapter for your ListView, and declare the Chronometer in the getView method for each row.
A custom adapter could be onle like this:
public class CustomAdapter extends BaseAdapter{
ArrayList<HashMap<String, String>> users;
Context context;
private static LayoutInflater inflater=null;
public CustomAdapter(MainActivity mainActivity, ArrayList<HashMap<String, String>> usersList) {
// TODO Auto-generated constructor stub
users = usersList;
context=mainActivity;
inflater = ( LayoutInflater )context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return items.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView tv;
...
Chronometer cr;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
//Create a custom layout for your row view with the chronometer on it and get it here
rowView = inflater.inflate(R.layout.custom_row_item, null);
holder.tv=(TextView) rowView.findViewById(R.id.textView1);
...
holder.cr=(Chronometer) rowView.findViewById(R.id.chronometer);
cr.start();
holder.tv.setText("GET THE TEXT YOU NEED FROM USERS LIST HERE");
return rowView;
}
}
Then declare and use your custom adapter like:
CustomAdapter myAdapter = new CustomAdapter(YourActivity.this, userList);
myList.setAdapter(myAdapter);
Hope it helps :)

Android RecyclerView not populating using Volley [duplicate]

Here is the code of the fragment in which I am setting a custom adapter to the list.
There no errors but the ListView is empty. I have implemented getCount() which returns right number of items in my ArrayList. I don't see ("Inside", "GetView") in the logcat
Fragment
public class ServiceCarListFragment extends Fragment {
private String url;
private ArrayList<CarDetail> carDetailList = new ArrayList<CarDetail>();
private CarListAdapter adapter;
private ListView mList;
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
url = getActivity().getIntent().getStringExtra("url");
new DownloadCarDetail().execute(url);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater.inflate(R.layout.fragment_service_car_list, container, false);
mList = (ListView) v.findViewById(R.id.list);
mList.setAdapter(adapter);
for (CarDetail car : carDetailList) {
// START LOADING IMAGES FOR EACH STUDENT
car.loadImage(adapter);
}
return v;
}
class DownloadCarDetail extends AsyncTask<String, String, ArrayList<CarDetail>> {
#Override
protected ArrayList<CarDetail> doInBackground(String... params) {
// TODO Auto-generated method stub
ArrayList<CarDetail> carDetailList = JsonParser.parseJson(params[0]);
return carDetailList;
}
#Override
protected void onPostExecute(ArrayList<CarDetail> carDetailList) {
// TODO Auto-generated method stub
ServiceCarListFragment.this.carDetailList = carDetailList;
Log.d("dccs", String.valueOf(ServiceCarListFragment.this.carDetailList.size()));
adapter = new CarListAdapter(getActivity(), ServiceCarListFragment.this.carDetailList);
Log.d("dccs", String.valueOf((adapter.getCount())));
}
}
}
CustomAdapter
public class CarListAdapter extends BaseAdapter {
private ArrayList<CarDetail> items = new ArrayList<CarDetail>();
private Context context;
public CarListAdapter(Context context, ArrayList<CarDetail> items) {
this.context = context;
this.items = items;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.d("Inside", "GetView");
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
ViewHolder holder = null;
CarDetail car = items.get(position);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.car_list_row, null);
holder = new ViewHolder();
holder.tvCarName = (TextView) convertView.findViewById(R.id.tvCarName);
holder.tvDailyPriceValue = (TextView) convertView.findViewById(R.id.tvWeeklyPriceValue);
holder.tvWeeklyPriceValue = (TextView) convertView.findViewById(R.id.tvWeeklyPriceValue);
holder.imgCar = (ImageView) convertView.findViewById(R.id.imgCar);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvCarName.setText(car.getCarName());
if (car.getImage() != null) {
holder.imgCar.setImageBitmap(car.getImage());
} else {
// MY DEFAULT IMAGE
holder.imgCar.setImageResource(R.drawable.ic_action_call);
}
return convertView;
}
static class ViewHolder {
TextView tvCarName;
TextView tvDailyPriceValue;
TextView tvWeeklyPriceValue;
ImageView imgCar;
}
}
The only reasons getView is not called are:
getCount returns 0.
you forget to call setAdapter on the ListView.
If the ListView's visibility (or its container's visibility) is GONE. Thanks to #TaynãBonaldo for the valuable input.
ListView is not attached to any viewport layout. That is, mListView = new ListView(...) is used without myLayout.addView(mListView).
In the onPostExcute, after you create a new instance of CarListAdapter I will suggest you to update the new instance to your ListView. Indeed you need to call again
mList.setAdapter(adapter);
Edit: setAdapter should be always called on the ui thread, to avoid unexpected behaviours
Edit2:
The same applies to RecyclerView. Make sure that
getItemCount is returning a value grater than 0 (usually the dataset size)
both setLayoutManager and setAdapter have to be called on the UI Thread
The visibility of the widget has to be set to VISIBLE
you must verify that the list has elements might have an error when adding items to your list .
To verify , use the method:
adapter.getCount();
I faced similar problem. Here is a simple work around to solve it:
In your onCreateView, you will have to wait before the view gets created. So change your lines from this:
mList = (ListView)v.findViewById(R.id.list);
mList.setAdapter(adapter);
CHANGE THE ABOVE TWO LINES INTO:
mList = (ListView)v.findViewById(R.id.list);
mList.post(new Runnable() {
public void run() {
mList.setAdapter(adapter);
}
});
Hope this will help others who would run into similar problem
You are missing the super class in the constructor. See my example below:
public AppDataAdapter(Activity a, int textViewResourceId, ArrayList<AppData> entries) {
super(a, textViewResourceId, entries);
this.entries = entries;
this.activity = a;
}
What you have been doing is
In your adapter
public CarListAdapter(Context context , ArrayList<CarDetail> items) {
this.context = context;
this.items = items;
}
in your Fragment
adapter = new CarListAdapter(getActivity(),ServiceCarListFragment.this.carDetailList);
I hope you will be using FragmentActivity
You need to call
adapter = new CarListAdapter(YOUR_ACTIVITY_CONTEXT, carDetailList);
where YOUR_ACTIVITY_CONTEXT will be your FragmentActivity
I had the same problem. And after trying all tips above my getView was still not being called. So I tried to remove the ScrollView that I used outside the ListView. Then the getView worked well. Just for add one more posibility. I Hope help someone.

android UnsupportedOperationException in ArrayAdapter<String>

I am trying to create an onDisimiss listener to my app as for now this is what i have
The activity
public class listview_test extends Activity {
ListView list;
String[] web = {
"Google Plus",
"Twitter",
"Windows",
} ;
Integer[] imageId = {
R.drawable.ic_launcher,
R.drawable.icon,
R.drawable.ic_launcher,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_test);
final CustomList adapter = new
CustomList(listview_test.this, web, imageId);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(listview_test.this, "You Clicked at " +web[+ position], Toast.LENGTH_SHORT).show();
}
});
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(
list,
new SwipeDismissListViewTouchListener.DismissCallbacks() {
#Override
public boolean canDismiss(int position) {
return true;
}
#Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
adapter.remove(adapter.getItem(position));
}
adapter.notifyDataSetChanged();
}
}
);
list.setOnTouchListener(touchListener);
// Setting this scroll listener is required to ensure that during ListView scrolling,
// we don't look for swipes.
list.setOnScrollListener(touchListener.makeScrollListener());
}
}
And the custom adapter
public class CustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] web;
private final Integer[] imageId;
public CustomList(Activity context,
String[] web, Integer[] imageId) {
super(context, R.layout.weather_item, web);
this.context = context;
this.web = web;
this.imageId = imageId;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.weather_item, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.city);
ImageView imageView = (ImageView) rowView.findViewById(R.id.info_image);
txtTitle.setText(web[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
For some reason every time i am swiping an item to dismiss it force closes and gives me this exception
java.lang.UnsupportedOperationException
In this line
adapter.remove(adapter.getItem(position));
java.lang.UnsupportedOperationException
is thrown when you back an Adapter by an array or non-modifiable List. Since you cannot change their size, deleting is impossible.
Instead, modify your Adapter so it accepts a List instead of an array and make sure that the List you pass off is fully flexible.
Something like
List <String> web = new ArrayList <String> ();
web.add ("Google Plus");
web.add ("Twitter");
//etc.
is enough to ensure a flexible list.
This means that your CustomList adapter should also call up to the superclass constructor that also accepts in a List, which in this case is
public ArrayAdapter (Context context, int resource, List<T> objects)
For more information refer to the ArrayAdapter documentation.

Making Listview Displaying only some items

Quick question, I wanted to make a listview that only displays certain items from an array, stored in a different class called MyArray. I would like the list view, in this case, to display only items whose title is 'example'. Is it possible to do this? I would also need to know this to make items deleted from the array ("" items) not appear in the listview. Thank you, I've included my whole listview code to avoid confusion! Hope this isnt too complicated of a question!
public class List extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
setListAdapter(new MyAdapter(this,
android.R.layout.simple_list_item_1, R.id.textView1,
MyArray.myarr));
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> adapter, View v, int position,
long arg3)
{
String index = (String)adapter.getItemAtPosition(position);
//Intent myIntent = new Intent(List.this, Show.class);
//List.this.startActivity(myIntent);
Intent i = new Intent(getApplicationContext(), Show.class);
i.putExtra("index", ""+position);
startActivity(i);
}
});
}
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource,
int textViewResourceId, String[] strings) {
super(context, resource, textViewResourceId, strings);
// TODO Auto-generated constructor stub
}
#Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflator = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE);
View row = inflator.inflate(R.layout.customlist, parent, false);
String[] items = MyArray.myarr;
ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
TextView tv = (TextView) row.findViewById(R.id.textView1);
if (items[position].equalsIgnoreCase("Example")){
}
else
{
tv.setText(items[position]);
iv.setImageResource(R.drawable.base);
}
return row;
}
}
}
I would not recommend the described approach in your question. If you don't need items in a ListView, don't pass them in your Array or List. Do some prefiltering. If you dynamically want to modify the contents of a ListView after it has been loaded, well, different topic and more sophisticated.
ListAdapter depends on the number of items in it, there are methods like getCount, getItem(int position) and you would have to implement all of those to avoid NULL - Pointer or index - out -of bound execptions.

Categories

Resources