how to find which button has been clicked in app widgets in android?
Posted
by
chrish
on Stack Overflow
See other posts from Stack Overflow
or by chrish
Published on 2012-04-11T05:19:46Z
Indexed on
2012/04/11
5:29 UTC
Read the original article
Hit count: 205
android
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
© Stack Overflow or respective owner