logo
Tags down

shadow

RecyclerAdapter set adapter position


By : ma12
Date : October 17 2020, 01:08 AM
wish helps you The solution to this issue is the developer had multiple search designs in the DBHelper each being triggered by different buttons on the search Activity this design in the DBHelper lead to multiple ArrayLists all with the same name this drove the RecycleAdapter crazy as it is bound to ArrayList so OLD Mr. Boolean to the rescue! Here is the revised design code features In the Search Activity declare public static Boolean use = false; and Import where needed import static com..MainActivity.use;
Here is the code for each search button
code :
    public void findAllData(View view){
    helper = new DBHelper(this);
    helper.getDataFromDB();
    use = false;
    // Set Mr. Boolean
    Intent intent = new Intent( MainActivity.this, ListActivity.class );
    // ListActivity shows Results of the Search
    startActivity( intent );
}

public void findSelect(View v){
    selectSTRING = etFromDate.getText().toString();
    // Get your Search variable
    helper = new DBHelper(this);
    helper.getDataFromDB();
    etToDate.setText(sendBACK);
    use = true;
    Intent intent = new Intent( MainActivity.this, ListActivity.class );
    startActivity( intent );
}
    /* Retrive ALL data from database table named "TABLE_INFO" */
public List<DBModel> getDataFromDB(){
    //String query = "SELECT * FROM " + TABLE_INFO + " WHERE " + Col_PURCHASE_DATE + " > 0 " + " ORDER BY " + Col_ID + " DESC ";
    /* Notice the SPACES before AND after the words WHERE ORDER BY ASC or DESC most of all the condition " > 0 "*/
    /* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*/
   Cursor cursor = null;
    List<DBModel> modelList = new ArrayList<>();
    if(use == true){
        String query = "SELECT * FROM " + TABLE_INFO + " WHERE " + Col_PURCHASE_DATE + " ='" + selectSTRING + "'";
        db = this.getWritableDatabase();
        cursor = db.rawQuery(query,null);
    }
    if(use == false){
        String query = "SELECT * FROM " + TABLE_INFO;
        db = this.getWritableDatabase();
        cursor = db.rawQuery(query,null);
    }

    if (cursor.moveToFirst()){

        do {
            DBModel model = new DBModel();
            model.setRowid(cursor.getInt(0));
            model.setStation_Name(cursor.getString(1));
            model.setDate_of_Purchase(cursor.getString(2));
            model.setGas_Cost(cursor.getString(3));
            modelList.add(model);

            int sz = modelList.size();
            int out =   model.setRowid(cursor.getInt(0));
            String out1 =  model.setStation_Name(cursor.getString(1));
            String out2 =  model.setDate_of_Purchase(cursor.getString(2));
            String out3 = model.setGas_Cost(cursor.getString(3));
            System.out.println("==============getDataFromDB ID "+out);
            System.out.println("==============getDataFromDB Station "+out1);
            System.out.println("==============getDataFromDB Date "+out2);
            System.out.println("==============getDataFromDB Cost "+out3);
            System.out.println("======= ======getDataFromDB SIZE "+sz);

        }while (cursor.moveToNext());
    }
    db.close();
    cursor.close();
    return modelList;
}


Share : facebook icon twitter icon

Get position from List Adapter


By : Kamlesh Joshi
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Use ArrayAdapter.getPosition(item) to get position of an item.

getting null value in position adapter


By : Umesh Kamboj
Date : March 29 2020, 07:55 AM
seems to work fine I need to fix this code Objects item = getItem(position); can you please help tell me why I am having getting null here its showing the result null , Instead of
code :
 object.setId(Integer.parseInt(cursor.getString(0)));
 object.setName(cursor.getString(1));
 object.setUrl(cursor.getString(2));
object.setId(cursor.getInt(cursor.getColumnIndex(OBJECT_ID)));
object.setName(cursor.getString(cursor.getColumnIndex(OBJECT_NAME)));
object.setUrl(cursor.getString(cursor.getColumnIndex(OBJECT_URL)));

How to get position and display data in detail activity using recycleradapter and firebase


By : Bags
Date : March 29 2020, 07:55 AM
this will help The best way to implement the onClick action in your adapter is to create an interface in your adapter and link it to your fragment by making it implement such interface, and then in the fragment you launch the new activity. I've refactored your adapter as such:
code :
public class SpecialAdapter extends RecyclerView.Adapter<SpecialAdapter.SpecialViewHolder> {

    List<ListItem> items;
    OnItemClickListener callback;

    public SpecialAdapter(List<ListItem> items, OnItemClickListener callback) {
        this.items = items;
        this.callback = callback;
    }

    @NonNull
    @Override
    public SpecialViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_item_tile, parent, false);
        return new SpecialViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull SpecialViewHolder holder, int position) {
        ListItem listItem = items.get(position);
        holder.username.setText(listItem.getUsername());
        holder.imageUrl.setVisibility(View.VISIBLE);
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    class SpecialViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public TextView username;
        public ImageView imageUrl;

        public SpecialViewHolder(View itemView) {
            super(itemView);

            username = itemView.findViewById(R.id.list_title);
            imageUrl = itemView.findViewById(R.id.list_avatar);

            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            callback.onItemClick(getAdapterPosition());
        }
    }

    public interface OnItemClickListener {
        void onItemClick(int pos);
    }
}
public class CategoryFragment extends Fragment implements SpecialAdapter.OnItemClickListener {
    private static final String TAG = "CategoryFragment";


    private RecyclerView recyclerView;
    private SpecialAdapter adapter;
    // private Adapter adapter;
    private List<ListItem> listItems;
    private FirebaseDatabase mFirebaseDatabase;
    private DatabaseReference myRef;

    private AdapterView.OnItemSelectedListener listener;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView =inflater.inflate(R.layout.recycler_view,container,false);
        listItems = new ArrayList<>();
        adapter = new SpecialAdapter(listItems, this);
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
        mFirebaseDatabase = FirebaseDatabase.getInstance();
        getFirebaseData();
        progressBar = rootView.findViewById(R.id.progressBar);
        recyclerView = rootView.findViewById(R.id.my_recycler_view);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        int tilePadding = getResources().getDimensionPixelSize(R.dimen.tile_padding);
        recyclerView.setPadding(tilePadding, tilePadding, tilePadding, tilePadding);
        recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        recyclerView.setAdapter(adapter);
        return recyclerView;

        //return rootView

    }

    private void getFirebaseData() {

        myRef = mFirebaseDatabase.getReference("Users");
        myRef.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                ListItem data = dataSnapshot.getValue(ListItem.class);
                listItems.add(data);
                adapter.notifyDataSetChanged();

            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {

            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {


            }
        });
    }

    @Override
    public void onItemClick(int pos) {

        Intent pDetail = new Intent(this.getContext(), ProfileDetail.class);

        ListItem item = listItems.get(pos);
        pDetail.putExtra(ProfileDetail.EXTRA_POSITION, item.getUserid());
        startActivity(pDetail);
    }
}
public class ListItem {

    private String details;
    private String imageurl;
    private String status;
    private String summary;
    private String userid;
    private String username;

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public String getImageurl() {
        return imageurl;
    }

    public void setImageurl(String imageurl) {
        this.imageurl = imageurl;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
public class ProfileDetail extends AppCompatActivity {
    private static final String TAG = "EXTRA_POSITION";
    public static final String EXTRA_POSITION = "profile_detail";
    private List<ListItem> listItems;
    private FirebaseDatabase mFirebaseDatabase;
    private DatabaseReference myRef;
    private TextView tvName, tvSummary, tvStatus, tvDetail;
    private ImageView ivImage;
    private ImageView ivImageCard;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.categorydetails);
        listItems = new ArrayList<>();
        ivImage = findViewById(R.id.userAvatar);
        ivImageCard = findViewById(R.id.header_img);
        tvName = findViewById(R.id.userProfileName);
        tvSummary = findViewById(R.id.ProfileSummary);
        tvStatus = findViewById(R.id.userStatus);
        tvDetail = findViewById(R.id.ProfileDetail);

        String userid = getIntent().getExtras().getString(ProfileDetail.EXTRA_POSITION);
        mFirebaseDatabase = FirebaseDatabase.getInstance();
        myRef = mFirebaseDatabase.getReference("Users");
        myRef.child(userid).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                ListItem item = (ListItem) dataSnapshot.getValue(ListItem.class);
                if(item!=null){
                   tvName.setText(item.getUsername());
                }

            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });


    }

}

How do I get the position from a spinner adapter?


By : Dinesh
Date : March 29 2020, 07:55 AM
like below fixes the issue I am filling a spinner with a generic ArrayList of cat Category type. , Use setOnItemSelectedListener like this

RecyclerView.Adapter<RecyclerAdapter.ViewHolder> confusion


By : Maksym
Date : March 29 2020, 07:55 AM
wish helps you I have been learning how to use RecyclerView in android studio. I came across a class extending "RecyclerView.Adapter < RecyclerAdapter.ViewHolder >". What is RecyclerAdapter.ViewHolder and why is it inside the brackets? , View holder objects:
Related Posts Related Posts :
  • Play Console Crash Reports (OutOfMemory)
  • Updated Android app built with Codename One instead of Android Studio
  • USB Communication with DTR/DTE enabled
  • This field leaks a context object
  • Best way to get Context in android for long running non Activity Class?
  • How to make a counter inside my tab layout like Whatsapp?
  • Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
  • Upload profile image for a user Firebase
  • Migrating from Xamarin to React Native: Xamarin SQLite Folder Path
  • Android Retrofit 2 wait on multiple requests
  • How do i make sure the Menu Item is always on the topbar?
  • android application with REST API connection
  • How can I validate user is already signed up?
  • Android - WebView back button
  • Customize the Status Bar
  • Android Cursor - Concatenate/Append a String
  • Accessing UI from methods outside onCreate
  • Updating collection(s) in Firebase that are created w/Cloud Functions
  • Ionic 2/3 - Easy way of ignoring other application/android directories when scanning device
  • Error while building cordova app
  • C# Double division returning infinity when is not supposed to
  • Android Studio layer-list render
  • SVG to PDF. How to?
  • Error Invalid DOUBLE
  • Broadcast Receiver not showing result when broadcasting from another app Activity
  • React Native - Sending information so as to receive a response for simple login screen but receiving JSON parse error in
  • TextToSpeech API
  • Room persistence library and Content provider
  • Invalid JSON String on response in android-apollo
  • XML layout design and code are not matching
  • RxAndroid, Retrofit 2 unit test Schedulers.io
  • How to Use FontAwesome Icon in Xamarin Android
  • Redundant resource referances in multiple R.java causes DexIndexOverflowException
  • Shared preferences isn't gettingBoolean properly
  • App keeps getting crashed after implementing Fragment with ListViews and a Custom ArrayAdapter
  • Getting wrong Location lat/long
  • Getting GPS location Consumes battery
  • Passing lambda as argument in Kodein
  • Recycle View in NestedScrollView
  • How to get sensor data in service when screen is turned off?
  • How to get a pointer to each frame data during preview into Android Camera2 API?
  • Delete shared preferences after app uninstall without using android:allowBackup="false"
  • How to make search filter with list item in react-native
  • Scheduling a local Notification with System Date and notifies without launching the App (Xamarin.Forms)
  • New Permissions Added Warning
  • phonegap build include git non npm plugin
  • How to avoid exiting full screen when pressing an EditText
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com