logo
down
shadow

how to reload listview from another activity (adapter) class


how to reload listview from another activity (adapter) class

By : Naimul Islam
Date : December 05 2020, 12:22 PM
I think the issue was by ths following , i have tried all the things but i cant get proper result,i also try , Good practice is use Interface
Create new Interface
code :
public interface MyCustomObjectListener {
      public void RefreshList();   
     //add parameter for delete if required  ex-   
     //public void RefreshList(String Item_id);     
  }
YourActivityName extends Activity implements MyCustomObjectListener 
   @Override
   public void RefreshList() {
        // Do your delete task and clear current List and get updated list task here
   }
((YourActivityName)mContext).RefreshList();


Share : facebook icon twitter icon
Navigation from one activity to another from listview adapter class

Navigation from one activity to another from listview adapter class


By : yaswanth naidu
Date : March 29 2020, 07:55 AM
How to finish an activity from a ListView adapter class?

How to finish an activity from a ListView adapter class?


By : Jafar Yor
Date : March 29 2020, 07:55 AM
With these it helps I have an activity with a ListView that loads data from a web service. I have a button in each list item which is loaded through custom adapter class. I am handling the button events in the adapter class. Now what I need is to finish the activity with ListView from the adapter class in the button click event.
code :
button.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    ((Activity)context).finish();

                }
            });
Insert images in listview of Adapter class according to the condition of Main Activity class

Insert images in listview of Adapter class according to the condition of Main Activity class


By : abdellah
Date : November 22 2020, 12:01 PM
With these it helps My title might seems unclear to you. , ok I managed to answer this way; In model class;
code :
public boolean isLocked() {

boolean returnCode = true;
// current date & time
Calendar now = Calendar.getInstance();

// parse date & time from database
String trainingStartDate = this.getDate();

String trainingStartTime = this.getStartTime();

String strDateTime = trainingStartDate + " " + trainingStartTime;

Calendar training = Calendar.getInstance();

try {
    training.setTime(new SimpleDateFormat("MM-dd-yyyy HH:mm")
            .parse(strDateTime));

    long difference = training.getTimeInMillis()
            - now.getTimeInMillis();

    if (difference < 15 * 60 * 1000) { // less than 15 minutes


        returnCode = false;
    }

} catch (java.text.ParseException e) {
    e.printStackTrace();
    //returnCode = false;
}

return returnCode;  
private void startTraining() {

// parse date & time from database
String trainingStartDate = SharedMemory.getInstance()
    .getCurrentTraining().getDate();

String trainingStartTime = SharedMemory.getInstance()
        .getCurrentTraining().getStartTime();

if ((currentTraining).isLocked()){
    Toast.makeText(
            getApplicationContext(),
            "The training starts on" + " " + trainingStartDate
                    + " at " + trainingStartTime,
            Toast.LENGTH_SHORT).show();
}else{
    Intent intent = new Intent(getApplicationContext(),
            TraineeListActivity.class);
    MainActivity.this.startActivity(intent);

    finish();

} }
// If training is locked, then display the lock picture
if (trainingsList.get(position).isLocked()) {

    holder.lockImage.setBackgroundResource(R.drawable.lock);

    // else display the unlock picture
} else {

    holder.lockImage.setBackgroundResource(R.drawable.unlock);
}
How to receive callback from Activity class into ListView Adapter class in android?

How to receive callback from Activity class into ListView Adapter class in android?


By : Mike Dressler
Date : March 29 2020, 07:55 AM
To fix this issue FIRST SOLUTION OWN LISTENER
It should be done by Listeners, create Listener interface in Activity, next implement interface in Adapter class. Set Adapter object as listener of Activity and last thing run Listener methods when You want to do something in Adapter.
code :
class Activity{

 private Listener listener;

 //your activity listener interface
 public interface Listener{

      onButtonClick();
 }


 private void setListener(Listener listener){

    this.listener=listener;
 }

 //example method
 private void youMethod(){

   YourAdapter adapter=new YourAdapter();//YourAdapter class implements Listener
   //here You say that adapter is You listener
   setListener(adapter);

   //bind button 
   Button button = (Button)findViewById(R.id.buttonName);
   button.setOnClickListener(new OnClickListener() {
     public void onClick(View v)
     {

        //run listener after button click
        buttonIsClicked();
        //or
        //listener.onButtonClick();
     } 
  });

 }

 private void buttonIsClicked(){
   //here use method
   listener.onButtonClick();
 }
}


//EXAMPLE ADAPTER
class YourAdapter implements Activity.Listener{

 //...adapter code

 void onButtonClick(){

   //your code on button click
 }
}
class Activity{


 //example method
 private void youMethod(){

   YourAdapter adapter=new YourAdapter();

   //bind button 
   Button button = (Button)findViewById(R.id.buttonName);
   //set adapter as onClickListener
   button.setOnClickListener(adapter);

 }

}


//EXAMPLE ADAPTER  
class YourAdapter implements OnClickLstener{

 //...adapter code

  public void onClick(View v)
  {

        //adpater code after click
  } 
}
button.setOnClickListener(new OnClickListener() {
     public void onClick(View v)
     {

        //use adapter
        adapter.onButtonClick();
     } 
  });


//EXAMPLE ADAPTER WITHOUT INTERFACE
class YourAdapter{

 //...adapter code

 void onButtonClick(){

   //your code on button click
 }
}
How to get Activity reference in ListView Adapter class?

How to get Activity reference in ListView Adapter class?


By : user1702398
Date : March 29 2020, 07:55 AM
With these it helps Having references of Activity in Adapter class is a bad approach. Anything that should be done within the activity class such as UI changes, displaying dialog etc. should not be done anywhere else but from the activity itself.
Solution:
code :
public interface MyListener {
     void doSomething(Params... params);
}
class MyActivity extends AppCompatActivity implements MyListener{ 
       new MyAdapter(this);  

       void doSomething(Params... params){
             //Request Permission here
       }
}
class MyAdapter extends .....{
      MyListener myListener;

      MyAdapter(Context mContext){
           if(mContext instanceOf MyListener)
                 myListener = (MyListener) mContext;
      }

      void anotherFunction(){
             myListener.doSomething(Params... params) 
     }
}
Related Posts Related Posts :
  • (android)Cant start activity => java.lang.RuntimeException: Unable to start activity ComponentInfo
  • android fragment replace fiil_parent with frame layout
  • Android Location Update not returning
  • MPAndroidChart: unwanted spacing between XAxis and data line
  • How to parse JsonArray values in Android
  • Lifecycle of tabs in Android
  • What are the problems in using Intent to pass objects from one activity to another
  • Android : Multi line text EditText inside BottomSheetDialog
  • set savedInstanceState Bundle in Activity
  • Change progressDialog font to custom on Android
  • Why POT textures work slower than non-pot?
  • PersonAPI Google+ "PERMISSION_DENIED" Error
  • Using UserDialogs in Android
  • Get lightness of ambiance with react-native?
  • Lines between code in android
  • Sort list in two differents ways
  • Android Studio Change Array Value
  • Disable webview browser tester ( android )
  • Are there any cons of creating Singleton class with static field to communicate between activities in Android?
  • Change fragment background on create view dynamically
  • Android Getting coordinates of an image
  • unfortunately project has stopped after adding admob ads
  • Error inflating Class ImageView on RecyclerView
  • Android percent layouts
  • App Inventor - Input an item to a list and then properly display the list
  • Android, CountDownTimer latency
  • How to detect MotionEvent.ACTION_DOWN in service Android
  • code in HTML for sharing content over Phone gap interacting with other app as like ACTION_SEND indent on the native andr
  • Android - Displaying decimal as formatted fraction (and vice versa)
  • Android -FAB Behaviour with half list
  • Enabling externalNativeBuild with ABI split
  • Issue with multiscreen design
  • Upload binary file with retrofit 2 in Android
  • R.layout is'nt recogized by the studio
  • android - RecyclerView updating every second and have a longPressListener
  • What's the best way (in Android dev) to consume REST API (in addition to Retrofit)?
  • Which Android SDK Packages do I need for Cordova and Android 4+
  • Android & Retrofit2 - posting image file in multipart request
  • Calabash directory structure for testing both Android and iOS
  • javafxports 8.60.7 - using Back button on Android - none exit application
  • Create file from drawable to send with sendbird
  • Firebase app integration error
  • Xamarin No resource found that matches the given name (at 'colorAccent' with value '@color/accent ')
  • Will Firebase provide tests for other OS and does it support manual testing?
  • Android - Obtain self-signed server certificate and add to trusted keystore
  • Error:(25, 46) error: @InjectViews must be a List or array
  • What is the difference between 'Make' and 'Gradle-aware Make'?
  • How to know if user has verified his/her email address
  • Importing Android-Download-Manager library results "failed to resolve"?
  • Showing particular area in google PlacePicker
  • Sharing pdf to Evernote not working in Android
  • Android : Google signin is not working in release mode
  • How to save an intent object and later retrieve it
  • Convert YUV Image into greyscale Image - Same Result as RGB to Grayscale?
  • bulkTransfer makes the application crash
  • How to aspect fill programmatically? [Android]
  • I lost my key store password, I want to update my app on plays store with same keystore
  • How to find the minimum and maximum dates from three tables even if there is no date in one table in android sqlite
  • Unparseable date: "10:40:54" (at offset 0)
  • Keep count of consumable in-app purchases using Firebase Realtime Database
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com