2016-08-02 37 views
0

我正在创建(或试图)当用户点击播放视频时弹出的警告对话框,如果存在已保存的简历点,则会给出选择重新开始,重新开始或取消操作。由于我想在对话框中包含恢复时间(例如“从08:32恢复播放”)带阵列适配器的警报对话框没有捕获点击

对话框显示正确的项目,格式正确,但点击时没有任何反应。我想知道我哪里出了问题。

Java代码:

final ArrayAdapter<String> itemVals = new ArrayAdapter<>(Docket.CURRENT_CONTEXT, 
     R.layout.adapter_simple_list_item, R.id.list_item); 

String optionStartBeginning = getString(R.string.media_play_no_resume); 
itemVals.add(optionStartBeginning); 

if (CastingBridge.getHasResume()) { 
    String optionResume = "Resume playback from "+ StringFormatter.intMsTimeToString(CastingBridge.RESUME_TIME); 
    itemVals.add(optionResume); 
} 

itemVals.add(getString(R.string.cancel)); 

AlertDialog.Builder builder = new AlertDialog.Builder(Docket.CURRENT_CONTEXT); 
builder.setTitle(R.string.resume_offer_title) 
     .setAdapter(itemVals, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       Log.i(TAG, "onClick: Chosen idx is "+ which); 
      } 
     }).setCancelable(true); 

AlertDialog alert = builder.create(); 
alert.show(); 

且布局文件R.layout.adapter_simple_list_item

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical"> 

    <com.rey.material.widget.TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:focusable="false" 
     style="@style/Material.Drawable.Ripple.Touch.MatchView" 
     app:rd_enable="true" 
     android:id="@+id/list_item" 
     android:text="@string/test_string" 
     android:paddingTop="20dp" 
     android:paddingBottom="20dp" 
     android:paddingLeft="24dp" 
     android:paddingRight="24dp" 
     android:textSize="18sp" /> 

</LinearLayout> 

上点击发生的唯一的事情是,这是印在logcat中:

D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN 

任何明显的错误,我不知道? 在此先感谢您的任何答案。

回答

1

Editted:

此代码工作

Java代码:

final ArrayAdapter<String> itemVals = new ArrayAdapter<String>(_A, 
        R.layout.check, R.id.list_item); 

      String optionStartBeginning = "No resaume"; 
      itemVals.add(optionStartBeginning); 

     /* if (CastingBridge.getHasResume()) { 
       String optionResume = "Resume playback from Here"; 
       itemVals.add(optionResume); 
      }*/ 

      itemVals.add("Cancel"); 

      AlertDialog.Builder builder = new AlertDialog.Builder(_A); 
      builder.setTitle("Simple") 
        .setAdapter(itemVals, new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          Log.i("", "onClick: Chosen idx is "+ which); 
         } 
        }).setCancelable(true); 

      AlertDialog alert = builder.create(); 
      alert.show(); 

布局文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/list_item" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:focusable="false" 
     android:paddingBottom="20dp" 
     android:paddingLeft="24dp" 
     android:paddingRight="24dp" 
     android:paddingTop="20dp" 
     android:text="Text" 
     android:textSize="18sp" /> 

</LinearLayout> 

我hvae这个上面的代码它的工作

+0

logcat中的“D/ViewRootImpl:ViewPostImeInputStage ACTION_DOWN”除点击事件之外仍然没有反应:( – mwieczorek

+0

您可以尝试使用Default TextView ? – MathaN

+0

与默认的TextView相同的结果(或缺少) – mwieczorek

0

我会尝试删除可获得焦点属性

android:focusable="false" 

或最终将其设置为 “真”

+0

我已经尝试设置为true,false,并删除它都在一起,还是同样的问题进行检查。唯一发生的事情是“D/ViewRootImpl:ViewPostImeInputStage ACTION_DOWN”出现在logcat中 – mwieczorek