I have code for ListwithImage list. But when i try to onclickItem shows with Dialog, but Dialog shows null. I implement onclickItemListener . I tried this code without image, Dialog shows selected list. But when i try with image, it won't work.
MyCode:
public class MainActivity extends Activity {
EditText edittext;
ListView listview;
String[] text = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten" };
int[] image = { R.drawable.one, R.drawable.two, R.drawable.three,
R.drawable.four, R.drawable.five, R.drawable.six, R.drawable.seven,
R.drawable.eight, R.drawable.nine, R.drawable.ten };
int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext = (EditText) findViewById(R.id.EditText01);
listview = (ListView) findViewById(R.id.ListView01);
listview.setAdapter(new MyCustomAdapter(text, image));
edittext.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after)
{
}
public void onTextChanged(CharSequence s, int start,
int before, int count)
{
textlength = edittext.getText().length();
text_sort.clear();
image_sort.clear();
for (int i = 0; i < text.length; i++)
{
if (textlength <= text[i].length())
{
if (edittext.getText().toString().
equalsIgnoreCase((String) text[i].subSequence(0, textlength)))
{
text_sort.add(text[i]);
image_sort.add(image[i]);
}
}
}
listview.setAdapter(new MyCustomAdapter
(text_sort, image_sort));
listview.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long rowId) {
// TODO Auto-generated method stub
listview.getItemAtPosition(position);
AlertDialog.Builder adb = new AlertDialog.Builder(
MainActivity.this);
adb.setTitle("List");
adb.setMessage(" selected Item is="
+ listview.getItemAtPosition(position));
adb.setPositiveButton("Ok", null);
adb.show();
}
});
}
});
}
class MyCustomAdapter extends BaseAdapter
{
String[] data_text;
int[] data_image;
MyCustomAdapter()
{
}
MyCustomAdapter(String[] text, int[] image)
{
data_text = text;
data_image = image;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<Integer> image)
{
data_text = new String[text.size()];
data_image = new int[image.size()];
for(int i=0;i<text.size();i++)
{
data_text[i] = text.get(i);
data_image[i] = image.get(i);
}
}
public int getCount()
{
return data_text.length;
}
public String getItem(int position)
{
return null;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.listview, parent, false);
TextView textview = (TextView) row.findViewById(R.id.TextView01);
ImageView imageview = (ImageView) row
.findViewById(R.id.ImageView01);
textview.setText(data_text[position]);
imageview.setImageResource(data_image[position]);
return (row);
}
}
your getting wrong values in Your Alert
wrong
+listview.getItemAtPosition(position));
right
adb.setMessage(" selected Item is="+text_sort.get(position).toString());
Try changing this:
adb.setMessage(" selected Item is= " + listview.getItemAtPosition(position));
To this:
adb.setMessage(" selected Item is= " + text_sort.get(position));
Related
I created a list-view which contains spinner and radio button on each list items and created edit-text to search list-view items based on spinner values on each list items.
How to implement search functionality using the spinner values in list items.
For example, when 1 is entered in edit-text all list items which contains 1 selected in spinner get listed.
ListAdapter.java
public class ListAdapter extends ArrayAdapter<DataModel>
{
private Activity myContext;
int selectedPos = -1;
int flag = 0;
int pos = 0;
public ListAdapter(Activity context, int textViewResourceId, DataModel[] objects)
{
super(context, textViewResourceId, objects);
myContext = context;
}
static class ViewHolder
{
protected DataModel data;
protected TextView selectedText;
protected Spinner spin;
protected RadioButton radioBtn;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View view = convertView;
final ViewHolder viewHolder;
if (view == null)
{
LayoutInflater inflator = myContext.getLayoutInflater();
view = inflator.inflate(R.layout.single_list_row, null);
viewHolder = new ViewHolder();
viewHolder.data = new DataModel(myContext);
viewHolder.selectedText = (TextView) view.findViewById(R.id.singleitem);
viewHolder.spin = (Spinner) view.findViewById(R.id.spinner1);
viewHolder.spin.setAdapter(viewHolder.data.getAdapter());
viewHolder.radioBtn = (RadioButton) view.findViewById(R.id.choice);
view.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.spin.setOnItemSelectedListener(new OnItemSelectedListener()
{
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
viewHolder.data.setSelected(arg2);
viewHolder.selectedText.setText(viewHolder.data.getText());
}
#Override
public void onNothingSelected(AdapterView<?> arg0)
{
}
});
if(flag != 1)
{
if (selectedPos == position)
{
viewHolder.radioBtn.setChecked(true);
}
else
{
viewHolder.radioBtn.setChecked(false);
}
}
else
{
viewHolder.radioBtn.setChecked(true);
}
viewHolder.radioBtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(flag != 1)
{
if (((RadioButton) view).isChecked())
{
selectedPos = position;
}
else
{
selectedPos = -1;
}
}
else
{
((RadioButton) view).setChecked(true);
}
notifyDataSetChanged();
}
});
viewHolder.selectedText.setText(viewHolder.data.getText());
view.setTag(viewHolder);
return view;
}
}
DataModel.java
public class DataModel
{
private int selected;
private int check;
private ArrayAdapter<CharSequence> adapter;
public DataModel(Context parent)
{
adapter = ArrayAdapter.createFromResource(parent, R.array.options, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}
public String getText()
{
return (String)adapter.getItem(selected);
}
public ArrayAdapter<CharSequence> getAdapter()
{
return adapter;
}
public int getSelected()
{
return selected;
}
public void setSelected(int selected)
{
this.selected = selected;
}
public int getCheck()
{
return check;
}
public void setCheck(int check)
{
this.check = check;
}
}
MainActivity.java
public class MainActivity extends Activity
{
int checkFlag = 1;
private ListView lv;
private ListAdapter d;
private EditText inputSearch;
private Button checkAllBtn;
private Button uncheckAllBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputSearch = (EditText) findViewById(R.id.inputSearch);
checkAllBtn = (Button) findViewById(R.id.checkall);
uncheckAllBtn = (Button) findViewById(R.id.uncheckall);
lv = (ListView) this.findViewById(R.id.listview1);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setTextFilterEnabled(true);
DataModel data = new DataModel(this);
DataModel data1 = new DataModel(this);
DataModel data2 = new DataModel(this);
DataModel data3 = new DataModel(this);
DataModel data4 = new DataModel(this);
DataModel data5 = new DataModel(this);
DataModel data6 = new DataModel(this);
DataModel data7 = new DataModel(this);
DataModel data8 = new DataModel(this);
DataModel data9 = new DataModel(this);
DataModel data10 = new DataModel(this);
d = new ListAdapter(this, R.layout.single_list_row, new DataModel[] { data, data1, data2, data3, data4, data5, data6, data7, data8, data9, data10 });
lv.setAdapter(d);
inputSearch.addTextChangedListener(new TextWatcher()
{
#Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3)
{
d.getFilter().filter(cs);
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{
}
#Override
public void afterTextChanged(Editable arg0)
{
}
});
checkAllBtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
d.flag = 1;
d.notifyDataSetChanged();
}
});
uncheckAllBtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
d.flag = 0;
d.notifyDataSetChanged();
}
});
}
}
I am displaying images from the gallery to my custom grid view with checkbox.
I have to select 6 images only.
I have the following code
public class MultiPhotoSelectActivity extends BaseActivity {
private ArrayList<String> imageUrls;
private DisplayImageOptions options;
private ImageAdapter imageAdapter;
CheckBox mCheckBox;
int pos;
ArrayList<String> selectedItems;
ArrayList<String> selectedimgs = new ArrayList<String>();
RelativeLayout rl_gallery_row,rl_gallery_async;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_image_grid);
//Bundle bundle = getIntent().getExtras();
//imageUrls = bundle.getStringArray(Extra.IMAGES);
rl_gallery_async = (RelativeLayout) findViewById(R.id.RelativeLayout_galleryas);
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
Cursor imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy + " DESC");
this.imageUrls = new ArrayList<String>();
for (int i = 0; i < imagecursor.getCount(); i++) {
imagecursor.moveToPosition(i);
int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
imageUrls.add(imagecursor.getString(dataColumnIndex));
System.out.println("=====> Array path => "+imageUrls.get(i));
}
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_image)
.showImageForEmptyUri(R.drawable.image_for_empty_url)
.cacheInMemory()
.cacheOnDisc()
.build();
imageAdapter = new ImageAdapter(this, imageUrls);
GridView gridView = (GridView) findViewById(R.id.gridview);
gridView.setAdapter(imageAdapter);
/*gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startImageGalleryActivity(position);
}
});*/
}
#Override
protected void onStop() {
imageLoader.stop();
super.onStop();
}
public void btnChoosePhotosClick(View v){
selectedItems = imageAdapter.getCheckedItems();
Toast.makeText(MultiPhotoSelectActivity.this, "Total photos selected: "+selectedItems.size(), Toast.LENGTH_SHORT).show();
Log.d(MultiPhotoSelectActivity.class.getSimpleName(), "Selected Items: " + selectedItems.toString());
}
public class ImageAdapter extends BaseAdapter {
ArrayList<String> mList;
LayoutInflater mInflater;
Context mContext;
SparseBooleanArray mSparseBooleanArray;
public ImageAdapter(Context context, ArrayList<String> imageList) {
// TODO Auto-generated constructor stub
mContext = context;
mInflater = LayoutInflater.from(mContext);
mSparseBooleanArray = new SparseBooleanArray();
mList = new ArrayList<String>();
this.mList = imageList;
}
public ArrayList<String> getCheckedItems() {
ArrayList<String> mTempArry = new ArrayList<String>();
for(int i=0;i<mList.size();i++) {
if(mSparseBooleanArray.get(i)) {
mTempArry.add(mList.get(i));
}
}
return mTempArry;
}
#Override
public int getCount() {
return imageUrls.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
pos = position;
if(convertView == null) {
convertView = mInflater.inflate(R.layout.row_multiphoto_item, null);
}
mCheckBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
final ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
rl_gallery_row = (RelativeLayout) findViewById(R.id.Relativelayout_gallery_row);
imageLoader.displayImage("file://"+imageUrls.get(position), imageView, options, new SimpleImageLoadingListener() {
#Override
public void onLoadingComplete(Bitmap loadedImage) {
Animation anim = AnimationUtils.loadAnimation(MultiPhotoSelectActivity.this, R.anim.fade_in);
imageView.setAnimation(anim);
anim.start();
}
});
mCheckBox.setTag(position);
//mCheckBox.setId(position);
mCheckBox.setChecked(mSparseBooleanArray.get(position));
mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
//mCheckBox.setId(position);
//holder.imageview.setId(position);
return convertView;
}
OnCheckedChangeListener mCheckedChangeListener = new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
mSparseBooleanArray.put((Integer) buttonView.getTag(), isChecked);
selectedItems = imageAdapter.getCheckedItems();
if(selectedItems.size() > 5 )
{
mCheckBox.setEnabled(false); // disable checkbox
}
}
};
}
}
Now i am not able to uncheck the checkbox automatically when the limit is crossed..
Please help..
I think your condition is not satisfied for unchecking the check box, try to put a toast inside your condition
Hello, Everybody. This is my code below, I'm using a custom font (arial) in my app, but something is wrong about my code typeface, maybe I put it in a wrong position (you all see it at the end of the code) or I missed some detail. I don't know. So, check it out! I need some help!
public class Listagem extends Activity {
EditText edittext;
ListView listview;
String[] text;
String[] text2;
int[] image = {
R.drawable.wolf;
R.drawable.cat;
};
int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<String> text2_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
text = getResources().getStringArray(R.array.text);
text2 = getResources().getStringArray(R.array.text2);
edittext = (EditText) findViewById(R.id.EditText01);
listview = (ListView) findViewById(R.id.ListView01);
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if ("Howl".equals(text[position])) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
player.start();
}
if ("Meow".equals(text[position])) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
player.start();
}
}
});
listview.setAdapter(new MyCustomAdapter(text, text2, image));
edittext.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
textlength = edittext.getText().length();
text_sort.clear();
text2_sort.clear();
image_sort.clear();
for (int i = 0; i < text.length; i++) {
if (textlength <= text[i].length()) {
if (edittext.getText().toString().equalsIgnoreCase((String) text[i].subSequence(0, textlength))) {
text_sort.add(text[i]);
text2_sort.add(text2[i]);
image_sort.add(image[i]);
}
}
}
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if ("Howl".equals(text_sort.get(position))) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
player.start();
}
if ("Meow".equals(text_sort.get(position))) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
player.start();
}
}
});
listview.setAdapter(new MyCustomAdapter(text_sort, text2_sort, image_sort));
}
});
}
class MyCustomAdapter extends BaseAdapter {
String[] data_text;
String[] data_text2;
int[] data_image;
MyCustomAdapter() {
}
MyCustomAdapter(String[] text, String[] text2, int[] image) {
data_text = text;
data_text2 = text2;
data_image = image;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<String> text2, ArrayList<Integer> image) {
data_text = new String[text.size()];
data_text2 = new String[text2.size()];
data_image = new int[image.size()];
for(int i=0;i<text.size();i++) {
data_text[i] = text.get(i);
data_text2[i] = text2.get(i);
data_image[i] = image.get(i);
}
}
public int getCount() {
return data_text.length;
}
public String getItem(int position) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater mInflater = getLayoutInflater();
convertView = mInflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.TextView01);
holder.text2 = (TextView) convertView.findViewById(R.id.TextView02);
holder.image = (ImageView) convertView.findViewById(R.id.ImageView01);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(data_text[position]);
holder.text2.setText(data_text2[position]);
holder.image.setImageResource(data_image[position]);
Typeface font1 = Typeface.createFromAsset(getAssets(), "arial.ttf");
TextView text2 = (TextView) findViewById(R.array.text2);text2.setTypeface(font1);
return convertView;
}
}
}
You can check this class
https://github.com/Neferetheka/Helper-Tools-for-Android/blob/master/FontManager.java
Then you just have to call the init method of the FontManager when your activity is created, and use the setTypeface method on your textviews
Everybody. I've tried to use a viewholder adapter, but I couldn't understand and my app stopped working. I need some help. I read some blogs that explained this. No success.
This is my code below and I just want how to modify this using a viewholder adapter or something else to my listview works fine with no lag. I'm more visua and if someone gives an example using my code, I'll appreciate for this. P.S: My Listview has more than 100 items, but I just reduced here to clarify and facilitate the view of my code.
public class Listagem extends Activity {
EditText edittext;
ListView listview;
String[] text;
String[] text2;
int[] image = {
R.drawable.wolf;
R.drawable.cat;
};
int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<String> text2_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
text = getResources().getStringArray(R.array.text);
text2 = getResources().getStringArray(R.array.text2);
edittext = (EditText) findViewById(R.id.EditText01);
listview = (ListView) findViewById(R.id.ListView01);
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if ("Howl".equals(text[position])) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
player.start();
}
if ("Meow".equals(text[position])) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
player.start();
}
}
});
listview.setAdapter(new MyCustomAdapter(text, text2, image));
edittext.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
textlength = edittext.getText().length();
text_sort.clear();
text2_sort.clear();
image_sort.clear();
for (int i = 0; i < text.length; i++) {
if (textlength <= text[i].length()) {
if (edittext.getText().toString().equalsIgnoreCase((String) text[i].subSequence(0, textlength))) {
text_sort.add(text[i]);
text2_sort.add(text2[i]);
image_sort.add(image[i]);
}
}
}
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if ("Howl".equals(text_sort.get(position))) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.howl);
player.start();
}
if ("Meow".equals(text_sort.get(position))) {
MediaPlayer player = MediaPlayer.create(Listagem.this, R.raw.meow);
player.start();
}
}
});
listview.setAdapter(new MyCustomAdapter(text_sort, text2_sort, image_sort));
}
});
}
class MyCustomAdapter extends BaseAdapter {
String[] data_text;
String[] data_text2;
int[] data_image;
MyCustomAdapter() {
}
MyCustomAdapter(String[] text, String[] text2, int[] image) {
data_text = text;
data_text2 = text2;
data_image = image;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<String> text2, ArrayList<Integer> image) {
data_text = new String[text.size()];
data_text2 = new String[text2.size()];
data_image = new int[image.size()];
for(int i=0;i<text.size();i++) {
data_text[i] = text.get(i);
data_text2[i] = text2.get(i);
data_image[i] = image.get(i);
}
}
public int getCount() {
return data_text.length;
}
public String getItem(int position) {
return null;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.listview, parent, false);
listview.setCacheColorHint(Color.TRANSPARENT);
listview.setFastScrollEnabled(true);
listview.setScrollingCacheEnabled(false);
TextView textview = (TextView) row.findViewById(R.id.TextView01);
TextView textview2 = (TextView) row.findViewById(R.id.TextView02);
Typeface font1 = Typeface.createFromAsset(getAssets(), "arial.ttf");
textview2.setTypeface(font1);
ImageView imageview = (ImageView) row.findViewById(R.id.ImageView01);
textview.setText(data_text[position]);
textview2.setText(data_text2[position]);
imageview.setImageResource(data_image[position]);
return row;
}
}
}
Your getView() method is wrong. It doesn't recycle views. That is the first problem you have to fix. Then if you want to improve the performance of the method by using the ViewHolder design pattern have a look to this tutorial
And please, follow the advises given to you in the above comments.
public class Great_listviewActivity extends Activity {
EditText edittext;
ListView listview;
Button search;
String[] text = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten" };
int[] image = { R.drawable.icon, R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon, R.drawable.icon, R.drawable.icon,
R.drawable.icon, R.drawable.icon, R.drawable.icon };
int textlength = 0;
ArrayList<String> text_sort = new ArrayList<String>();
ArrayList<Integer> image_sort = new ArrayList<Integer>();
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
search = (Button) findViewById(R.id.Button01);
edittext = (EditText) findViewById(R.id.EditText01);
listview = (ListView) findViewById(R.id.ListView01);
listview.setAdapter((ListAdapter) new MyCustomAdapter(text, image));
search.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
textlength = edittext.getText().length();
text_sort.clear();
image_sort.clear();
for (int i = 0; i < text.length; i++)
{
if (textlength <= text[i].length())
{
if (edittext.getText().toString().equalsIgnoreCase((String) text[i].subSequence(0, textlength)))
{
text_sort.add(text[i]);
image_sort.add(image[i]); } }
} //end of for loop
listview.setAdapter(new MyCustomAdapter(text_sort, image_sort));
} //end of onClick
}); //end of search click
}
class MyCustomAdapter extends BaseAdapter implements ListAdapter
{
String[] data_text;
int[] data_image;
MyCustomAdapter()
{
}
MyCustomAdapter(String[] text, int[] image)
{
data_text = text;
data_image = image;
}
MyCustomAdapter(ArrayList<String> text, ArrayList<Integer> image)
{
data_text = new String[text.size()];
data_image = new int[image.size()];
for (int i = 0; i < text.size(); i++) {
data_text[i] = text.get(i);
data_image[i] = image.get(i);
}
}
public int getCount()
{
return data_text.length;}
public String getItem(int position)
{
return null;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.listview, parent, false);
TextView textview = (TextView) row.findViewById(R.id.TextView01);
ImageView imageview = (ImageView) row.findViewById(R.id.ImageView01);
textview.setText(data_text[position]);
imageview.setImageResource(data_image[position]);
return (row);
}
It got tripped up at the line listview.setAdapter((ListAdapter) new MyCustomAdapter(text, image)); It just says Source Not found. It leaves no clue of what could be wrong.
It just says Source Not found
This could've given you a clue to search for that message on this site. Please have a look at the answer to this question, it may help you to figure out what's going on.
have you checked whether the correct java compiler is attached to the Eclipse Environment.