2013-12-25 2 views
0

У меня есть файл XML, определенный следующим образом:Ввод уведомления из XML-файла

<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> 

Я пытаюсь добавить этот XML-файл в уведомлении, и это то, что я до сих пор:

 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()); 

Но когда я пытаюсь добавить его так, я получаю сообщение об ошибке «Неверное уведомление, отправленное из пакета [имя пакета]. Не удалось развернуть RemoteViews«

Может кто-нибудь сказать мне, что я делаю неправильно здесь. Благодаря!

ответ

0

RemoteView макет не поддерживает EditText. Попробуйте заменить его на TextView.
Вы можете обратиться к this list для просмотров/макеты поддерживаемых RemoteView

Надежда, что помогает

+0

Но в соответствии с этим, он говорит EditText можно поставить на панели уведомлений. http://stackoverflow.com/questions/12764281/android-edittext-on-status-notification Возможно, что-то похожее на RemoteView? – user2998771

+0

Также в любом случае я могу сделать textview доступным для редактирования, чтобы получить пользовательский ввод? – user2998771

+0

Ну, сообщение, о котором вы говорите, упоминается только на Android> 4.1 (API 16). Я все еще не уверен, что это сработает. И для создания «TextView» редактируемого - нет, это не сработает. – kiruwka

Смежные вопросы