android-adapter

onActivityResult in RecyclerView.Adapter<MyAdapter.MyViewHolder>

£可爱£侵袭症+ 提交于 2019-12-06 15:24:33
问题 I tried to open gallery from my adapter. emp_photo_edit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); ((EmployeeActivity)context).startActivityForResult(i, 2017); } }); Then i want to show that choosen image into my imageview in my recycycleview , how to do that? Because i cant add onActivityResult on my adapter . Thanks in advance Edit My Full

Android : Custom adapter fails to reload list view on activity resume

倾然丶 夕夏残阳落幕 提交于 2019-12-06 14:33:51
问题 I am trying to display received messages using custom adapter on list view , until now everything is working fine , but when I press back and come back and launch this activity again , only message send works but received messages cannot be displayed on the list view. Steps I have done so far : Use debugger to find out if message is not empty, messages are received and not empty. Use debugger inside receives() function , it turns out on first launch of activity looper.loop() function gives

Efficient adapter has java.lang.ClassCastException?

纵然是瞬间 提交于 2019-12-06 14:08:16
After watching here I try to implement my own efficient adapter, My ViewHolder class almost same: static class ViewHolder { ImageButton button; TextView txtView; } getView method look like: private void getView(...) { if(convertView == null) { convertView = LayoutInflater.from( parent.getContext()).inflate(R.layout.linear_container, parent, false); holder = new ViewHolder(); convertView.setTag(holder); } else { // erro line holder = (ViewHolder) convertView.getTag(); } LinearLayout llCustomImgViewContainer = (LinearLayout) convertView .findViewById(R.id.llContainer); llCustomImgViewContainer

ListView Adapter with multiple Item layouts

青春壹個敷衍的年華 提交于 2019-12-06 13:06:27
I'm looking at adding a listview to my Android application with a thumbnail image. The thumbnail on the left and text on the right. Is there any way of populating the list view with seperate xml files, for example, could I have separate xmls for Austria, UK, USA etc and add them to the listview? The reason I ask is, I plan to reuse the individual countries multiple times, as in, shown in an A to Z but then again by Continent etc. If this is possible, could I get an example of how this is done or a link with a tutorial etc? Thanks Do you really want separate .xml files? Or do you want to reuse

Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object ref [duplicate]

删除回忆录丶 提交于 2019-12-06 10:39:47
This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 3 years ago . I'm trying to display data in a listView. I have the current code attempting to take an array that is passed in from the myDatabase class, and then display this within my listView. However I got an error : "Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference". My code is working in main activity when I remove the code for the listView element, in it's place I've tested to ensure the passed

Listview, custom adapter and checkboxes

℡╲_俬逩灬. 提交于 2019-12-06 10:24:45
i got an issue with my adapter. Here is the code: @Override public View getView(final int position, final View convertView, final ViewGroup parent) { final ViewHolder viewHolder; View view = convertView; if (view == null) { view = LayoutInflater.from(mContext).inflate(R.layout.row, parent, false); viewHolder = new ViewHolder(); viewHolder.textTitle = (TextView) view.findViewById(R.id.title); viewHolder.checkBox = (CheckBox) view.findViewById(R.id.checkBox); viewHolder.checkBox.setTag(position); view.setTag(viewHolder); viewHolder.imageView = (ImageView) view.findViewById(R.id.activity

listview count vs adapter count in android

不打扰是莪最后的温柔 提交于 2019-12-06 08:51:07
问题 Why do listview.getChildCount() and adapter.getCount() return different values? I have an onScroll method and from within it, if I call the methods above, each return different values. Does anyone know why? 回答1: ListView.getChildCount() returns the number of Views on the screen. Adapter s getCount() returns the total number of objects in your list. getChildCount() getCount() You might have 50 String s in say an ArrayAdapter but only 10 are drawn on the screen at the current moment so your

Custom android adapter with generic class

和自甴很熟 提交于 2019-12-06 07:26:27
I'm trying to create a generic adapter in Android, so i can not write it over and over. The thing is,it's working, but it's not recycling very well, it displays what i want but when i scroll, it's not in the same order. public class CustomListViewAdapter<T> extends BaseAdapter { private List<T> objects; private LayoutInflater inflater; private int resources; private AdapterCommand<T> listener; private ViewHolder h; public CustomListViewAdapter(Context context, List<T> objects, int resources, AdapterCommand<T> listener, ViewHolder h) { this.h = h; this.listener = listener; this.resources =

Android - why lost values EditText when scrolled RecyclerView?

走远了吗. 提交于 2019-12-06 06:31:21
I am using from bellow code for converting numbers to currency format when text changes but when I scrolled the recyclerView I lost true data. What can I do : public class ManagePriceProductsAdapter extends RecyclerView.Adapter<ManagePriceProductsAdapter.ViewHolder> { private List<ManagePriceProductsModel.DataValue> managePriceProductsModelList; private Context context; private getListDiscountInterface getListDiscountInterface; private int vendorId = -1; public ManagePriceProductsAdapter(Context context, List<ManagePriceProductsModel.DataValue> managePriceProductsModelList,

How to get the selected Tab of a viewPager?

瘦欲@ 提交于 2019-12-06 04:43:43
I created a viewpager using the lib viewpagerindicator. The activity extends FragmentActivity, so I have a problem to get which tab is selected. My adapter is given by the code below. class GoogleMusicAdapter extends FragmentPagerAdapter implements IconPagerAdapter { public GoogleMusicAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { // add each fragment in the right place if(position == 0){ // return TestFragment.newInstance(CONTENT[(position + 1) % CONTENT.length]); return StudentTaskFragment.newInstance(); } else if(position == 1){ return