Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i listen a button on widget
    primarykey
    data
    text
    <p>First of all, i am sory because of my english is bad and i am new in android.İ have a problem,i want to a calculator widget on android but my code not work. i firstly apply button click only one button which idname is buttun1. that my code please help me. thanks.</p> <pre><code>package widgetcalculator; import com.example.widgetcalculator.R;, public class Calculator extends AppWidgetProvider { RemoteViews rmViews; ComponentName cmName; AppWidgetManager appWidgetManager; public static String WIDGET_BUTTON = "com.example.widgetcalculator.button1"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); rmViews = new RemoteViews(context.getPackageName(),R.layout.main); appWidgetManager = this.appWidgetManager; Intent intent = new Intent(WIDGET_BUTTON); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); rmViews.setOnClickPendingIntent(R.id.button1, pendingIntent ); } @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub super.onReceive(context, intent); RemoteViews rmViews=new RemoteViews(context.getPackageName(),R.layout.main); if (WIDGET_BUTTON.equals(intent.getAction())) { //your code here rmViews.setTextViewText(R.id.textView1, "1"); cmName = new ComponentName(context, Calculator.class); appWidgetManager.updateAppWidget(cmName, rmViews); } } } </code></pre> <p>and my mainfest.xml </p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.widgetcalculator" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;receiver android:name=".Calculator" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="com.example.widgetcalculator.button1" /&gt; &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;, &lt;/intent-filter&gt; &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" /&gt; &lt;/receiver&gt; &lt;/application&gt; </code></pre> <p></p> <p>and my layout/ main.xml file</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="60dp" android:text="0" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" /&gt; &lt;Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3" /&gt; &lt;Button android:id="@+id/buttontop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4" /&gt; &lt;Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5" /&gt; &lt;Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6" /&gt; &lt;Button android:id="@+id/buttoncik" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="7" /&gt; &lt;Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="8" /&gt; &lt;Button android:id="@+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="9" /&gt; &lt;Button android:id="@+id/buttoncarp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="x" /&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/buttonsil" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="C" /&gt; &lt;Button android:id="@+id/button0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0" /&gt; &lt;Button android:id="@+id/buttonnokta" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="." android:textStyle="bold" /&gt; &lt;Button android:id="@+id/buttonbol" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="%" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload