Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:33:06+00:00 2026-06-01T14:33:06+00:00

I want to design simple app widget which has two textview and two button

  • 0

I want to design simple app widget which has two textview and two button for previous/next. I am getting difficult to handle button click in app widget. Actually my desire is,if user click on previous button i want to show previous value and if user click on Next button i want to show next value from database. How to know which button is clicked?
here i register button click listener like this

  public static class UpdateWidgetService extends IntentService {

    public UpdateWidgetService() {
        super("UpdateWidgetService");

    }

    @Override
    protected void onHandleIntent(Intent intent) {
        AppWidgetManager appWidgetManager = AppWidgetManager
                .getInstance(this);

        int incomingAppWidgetId = intent.getIntExtra(EXTRA_APPWIDGET_ID,
                INVALID_APPWIDGET_ID);
        if (incomingAppWidgetId != INVALID_APPWIDGET_ID) {
            updateOneAppWidget(appWidgetManager, incomingAppWidgetId);

        }

    }


    private void updateOneAppWidget(AppWidgetManager appWidgetManager,
            int appWidgetId) {
        DatabaseManager dbManager = new DatabaseManager(this);

        dbManager.open();
        String contactNumber, date, status, message;
        ArrayList<QueuedMessage> listOfQuedMessage =        (ArrayList<QueuedMessage>) dbManager
                .fetchContactNumber();
        if (listOfQuedMessage.size() == 0)
            Log.i("Db", "null");
        else{
        date = dbManager.fetchDate();
        message = dbManager.fetchMessage();
        status = dbManager.fetchStatus();

        dbManager.closeDatabase();

        RemoteViews views = new RemoteViews(this.getPackageName(),
                R.layout.schdulesms_appwidget_layout);
        views.setTextViewText(R.id.to_appwidget_saved_data,
                listOfQuedMessage.get(count).contacNumber);
        views.setTextViewText(R.id.date_appwidget_saved_data, date);
        views.setTextViewText(R.id.status_appwidget_saved, status);
        views.setTextViewText(R.id.message_appwidgset_saved_data, message);

                    **//here i want do**
                   if(button1){
               btnNxtClick(views, appWidgetId,listOfQuedMessage.size());
                    }else{
                 btPrevClick(views, appWidgetId, listOfQuedMessage.size());
                    }

        appWidgetManager.updateAppWidget(appWidgetId, views);
        }

    }

    private void btnNxtClick(RemoteViews views, int appWidgetId,int sizeOfList) {
        Intent btnNextIntent = new Intent(this, this.getClass());
        btnNextIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId);
        PendingIntent btnNextPendingIntent = PendingIntent.getService(this,
                0, btnNextIntent,    PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.btnNext, btnNextPendingIntent);

    }
    private void btPrevClick(RemoteViews views, int appWidgetId,int sizeOfList) {
        Intent btnNextIntent = new Intent(this, this.getClass());
        btnNextIntent.putExtra(EXTRA_APPWIDGET_ID, appWidgetId);
        PendingIntent btnNextPendingIntent = PendingIntent.getService(this,
                0, btnNextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.btnPrev, btnNextPendingIntent);

    }

}

can anyone help me out from this problem?? thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:33:07+00:00Added an answer on June 1, 2026 at 2:33 pm

    know which button is clicked follow these Steps:

    step 1:
    Register two reciver for btnNext and btnPrev

     <intent-filter >
     <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
     <action android:name="com.app.example.MyWidget.ACTION_WIDGET_CLICK_NEXT"/>
     <action android:name="com.app.example.MyWidget.ACTION_WIDGET_CLICK_PREV"/>
     </intent-filter>
    

    step 2:
    for btnNext and btnPrev action strings:

    public class MyWidget extends AppWidgetProvider {
    public static String ACTION_WIDGET_CLICK_NEXT = "Action_nextbtn";
    public static String ACTION_WIDGET_CLICK_PREV = "Action_prevbtn";
    }
    

    step 3:
    In onReceive

    @Override
            public void onReceive(Context paramContext, Intent paramIntent)
            {
              String str = paramIntent.getAction();
                if (paramIntent.getAction().equals(ACTION_WIDGET_CLICK_NEXT)) {
                    updateWidgetState(paramContext, str);   
                }
                if (paramIntent.getAction().equals(ACTION_WIDGET_CLICK_PREV)) {
                    updateWidgetState(paramContext, str);   
                }
            }
    

    step 4:
    Make a method for update widget states:

    static void updateWidgetState(Context paramContext, String paramString)
              {
                RemoteViews localRemoteViews = buildUpdate(paramContext, paramString);
                ComponentName localComponentName = new ComponentName(paramContext, MyWidget.class);
                AppWidgetManager.getInstance(paramContext).updateAppWidget(localComponentName, localRemoteViews);
              }
    

    Step 5:

    private static RemoteViews buildUpdate(Context paramContext, String paramString)
              {
    
                rview = new RemoteViews(paramContext.getPackageName(), R.layout.widget_layout);
                Intent activebtnnext = new Intent(paramContext, MyWidget.class);
                active.setAction(ACTION_WIDGET_CLICK_NEXT);
                PendingIntent configPendingIntentnext = PendingIntent.getBroadcast(paramContext, 0, activebtnnext , 0);
                rmViews.setOnClickPendingIntent(R.id.btnNext, configPendingIntentnext);
    
                Intent activeprevbtn = new Intent(paramContext, MyWidget.class);
                active.setAction(ACTION_WIDGET_CLICK_PREV);
                PendingIntent configPendingIntentprev = PendingIntent.getBroadcast(paramContext, 0, activeprevbtn , 0);
                rmViews.setOnClickPendingIntent(R.id.btnprev, configPendingIntentprev);
                if(parmString.equals(ACTION_WIDGET_CLICK_NEXT))
                {
    
                 //
    
                }  
                if(parmString.equals(ACTION_WIDGET_CLICK_PREV))
                {
    
                 //
    
                }           
                 return rview; 
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We want to design a simple domain specific language for writing test scripts to
I just want to design this very simple website. Basically there are multiple pages
I want to design a c# program which can run program a 3rd exe
I want to design a music player with ListBox has 2 rows to show
I want to design an app that needs user to input few things like
I try to design my app to find database entries which are similar. Let's
Suppose we want to design a Java EE web application system which is expected
I want design my startup screen with progress bar. But I don't how to
That's my question, I want design all the interface of my application within an
I want to design a web page with a banner and an iframe. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.