0

I have an xml file defined as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="fill_parent"  
android:layout_height="fill_parent"  
android:gravity="center"  
android:orientation="horizontal" >  
  <EditText  
  android:id="@+id/view1"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:text="notif"  
 />  
 <Button  
  android:id="@+id/button1"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:text="Send" />  
</LinearLayout> 

I am trying to add this xml file to a notification and this is what I have so far:

     RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
 R.layout.custom_layout);
 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
 context).setSmallIcon(R.drawable.ic_launcher).setContent(
 remoteViews);
 // Creates an explicit intent for an Activity in your app  
 Intent resultIntent = new Intent(context, Receiver.class);
 TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
 stackBuilder.addNextIntent(resultIntent);
 PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
 PendingIntent.FLAG_UPDATE_CURRENT);
 remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);

 NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
 // mId allows you to update the notification later on.  
 mNotificationManager.notify(100, mBuilder.build());

But when I try to add it like this, I get the error "Bad notification posted from package [package name]. Couldn't expand RemoteViews"

Can someone tell me what I am doing wrong here. Thanks!

Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85

1 Answers1

0

RemoteView's layout does not support EditText. Try replacing it with a TextView.
You can refer to this list for views/layouts supported by RemoteView

Hope that helps

Community
  • 1
  • 1
kiruwka
  • 9,250
  • 4
  • 30
  • 41
  • But according to this, it says EditText can be put on the notification panel. http://stackoverflow.com/questions/12764281/android-edittext-on-status-notification Is there something similar to RemoteView perhaps? – user2998771 Dec 25 '13 at 18:37
  • Also anyway I can make a textview editable to get user input? – user2998771 Dec 25 '13 at 18:41
  • Well, the post you refer to mentions it is only possible on Android > 4.1 (API 16). I am still not sure it will work though. And for the making `TextView` editable - no, it won't work. – kiruwka Dec 26 '13 at 09:06