2016-12-26 1 views
-1

私は初心者です。それはそう多くのボタン、スピナー、エディットテキストなどを持っているとして、私は、それが養うために、いくつかの命令を持って警告ダイアログボックスを開く必要があり、リストから任意の項目をクリックした場合ので、私は活動としてそれを作ることを決めた私は、1つのリストビューを持っています。 listViewアイテムをクリックすると、警告ダイアログボックスと同様のアクティビティを開くことはできますか?

は、今のところ私はちょうど私がそのコーディングを行いますか&その後、それが動作するかどうかを確認するためにxmlファイルを作りました。今私の質問はどのようにalertdialogボックスとしてそれを作ることができ、アイテムがリストビューでクリックすると開きます。

ここ

は私のサブメニューの活動です:

@Override 
    public void onItemClick(AdapterView<?> parent, View view, 
          int position, long rowId) { 
     final AlertDialog customDialog = new AlertDialog.Builder(SubMenu.this).create(); 
     final LayoutInflater inflater = getLayoutInflater(); 
     final View dialogView = inflater.inflate(R.layout.popup 
       , null); 
     customDialog.setView(dialogView); 
     // set the custom customDialogimation components - text, image and button 
     final TextView tvDistance = (TextView) dialogView.findViewById(R.id.h2); 


     final Button okbtn=(Button)dialogView.findViewById(R.id.ok) ; 
     okbtn.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 

       customDialog.dismiss(); 

      } 
     }); 

     final Button cnclbtn=(Button)dialogView.findViewById(R.id.canc) ; 

     cnclbtn.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 

       customDialog.dismiss(); 

      } 
     }); 
    } 
    } 

uは上記を参照できるように私はポップアップを使用してみましたが、thtsは動作していないuがいずれかのボタンをクリックするか、選択した場合など

ここに私のmydialog.xmlは以下のとおりです。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:background="#FFFFFF" 
    android:gravity="start" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="10dp"> 

     <ImageView 
      android:id="@+id/desimage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:src="@drawable/logo" /> 

     <TextView 
      android:id="@+id/h1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:text="Chicken Pizza Small" 
      android:textSize="21sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/h2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:text="Chicken Pizza Small Combo" 
      android:textColor="#8c8181" 
      android:textSize="16sp" /> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="10dp" 
      android:orientation="horizontal" 
      android:weightSum="10"> 

      <Button 
       android:id="@+id/quant" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginRight="10dp" 
       android:layout_weight="3" 
       android:background="@drawable/mybtn" 
       android:text="Quantity" 
       android:textAllCaps="false" 
       android:textColor="#ffffff" /> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_weight="7" 
       android:background="@drawable/stroke_button" 
       android:orientation="horizontal" 
       android:weightSum="3"> 

       <Button 
        android:id="@+id/incr" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:text="-" 
        android:background="@color/colorwhite" 
        android:textColor="#FFA726" 
        android:textSize="25dp" /> 

       <View 
        android:layout_width="1dp" 
        android:layout_height="match_parent" 
        android:background="#c0c0c0" /> 

       <EditText 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:gravity="center" 
        android:inputType="number" 
        android:text="5" /> 

       <View 
        android:layout_width="1dp" 
        android:layout_height="match_parent" 
        android:background="#c0c0c0" /> 

       <Button 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="1" 
        android:background="@color/colorwhite" 
        android:gravity="center" 
        android:text="+" 
        android:textColor="#FFA726" 
        android:textSize="25dp" /> 

      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp"> 

      <CheckBox 
       android:id="@+id/sl" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="SL" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/s" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="S" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/m" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="M" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/L" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="l" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

      <CheckBox 
       android:id="@+id/f" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:buttonTint="#c0c0c0" 
       android:text="F" 
       android:textColor="#8c8181" 
       tools:targetApi="lollipop" /> 

     </LinearLayout> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:background="#c0c0c0" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:orientation="horizontal"> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginRight="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/stroke_button" 
       android:orientation="vertical" 
       android:paddingBottom="5dp" 
       android:paddingTop="5dp"> 

       <Spinner 
        android:id="@+id/spinner1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="5dp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/stroke_button" 
       android:orientation="vertical" 
       android:paddingBottom="5dp" 
       android:paddingTop="5dp"> 

       <Spinner 
        android:id="@+id/spinner2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="5dp" /> 
      </LinearLayout> 
     </LinearLayout> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:text="SPECIAL INSTRUCTIONS" 
      android:textSize="16sp" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/stroke_button" 
      android:padding="@dimen/fab_margin1"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@android:color/transparent" 
       android:gravity="top" 
       android:inputType="textCapSentences|textMultiLine" 
       android:lines="5" 
       android:maxLines="5" 
       android:padding="2dp" 
       android:textColor="#c0c0c0" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp"> 

      <Button 
       android:id="@+id/canc" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/mybutton2" 
       android:text="Cancel" 
       android:textColor="#ffffff" /> 

      <Button 
       android:id="@+id/ok" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_weight="1" 
       android:background="@drawable/mybtn" 
       android:text="Ok" 
       android:textColor="#ffffff" /> 


     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

任意のリストビューアイテムをクリックするとダイアログとして表示されます。親切に助けてください。

答えて

0

をオーバーライドする必要があり.. ListView項目のクリックでAlertDialogを表示することができます。以下のコードを使用して結果を得る:

@Override 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long rowId) { 
    final AlertDialog customDialog = new AlertDialog.Builder(SubMenu.this).create(); 
      final LayoutInflater inflater = getLayoutInflater(); 
      final View dialogView = inflater.inflate(R.layout.mydialog, null); 
      customDialog.setView(dialogView); 
      // set the custom customDialogimation components - text, image and button 
      final TextView tvDistance = (TextView) dialogView.findViewById(R.id.h2); 
customDialog.show(); 
    } 

dialogView.findViewByIdを常に使用するダイアログレイアウトのコンポーネントを参照する。これにより、すべてのコンポーネントアクションを記述できます。

+0

私はgetActivityに赤い線を取得しています() –

+0

は、それを削除します。私の編集したコードを見てください。 –

+0

はい、その作業...しかし、私はすべてここで私は、サーバーから画像を呼び出す必要がありますので、ちょうどデモ画像がある示されている画像は、ダイアログボックスで、ここでコーディング,,私は、このダイアログでのみそれを行うことができますすることができます –

0

スクロールビューをFrameLayoutの内側に置き、2番目の子をスクロールビューの上に表示される何らかの並べ替え(RelativeLayoutとしましょう)にします フレームレイアウトは、2番目の子を最初のものの前に置きます。デフォルトでは、2番目の子が表示されるようにします:リストビューにクリックがあったときに彼を見えるようにし、親のサイズを親にして余白を追加して、後ろのものを見ることができます。

例:活動を行う

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"> 
<ScrollView 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:background="#FFFFFF" 
    android:gravity="start" 
    android:orientation="vertical"> 
    ... 
    ... 
    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="gone"></RelativeLayout> 
</FrameLayout> 
-1

は私が考えるかなり良いアイデアではありません。あなたはカスタムを試しますAlertDialog?あなたはこのリンクをチェックアウトすることができますhttps://developer.android.com/guide/topics/ui/dialogs.html

あなたのカスタムalertDialogでは、あなた自身のレイアウトを使用することができます。私を信頼する私は指示どおりに働いて、それは働いた!

+0

OKますが、アラートTHERでは、それが適切にダイアログ上で動作します,,すべてchboxなど、スピナーをbのでしょうか? –

+0

はい、明らかに、あなただけのレイアウトを作る、指示に従って 'LayoutInflater'を使用してレイアウトを膨らませる、あなたの' AlertDialogBu​​ilder'に必要なメソッドを記述し、あなたが行ってもいいです。 –

0

あなたはダイアログとして、カスタムレイアウトを示すために使用AlertDialogあなたonItemClick方法

@Override 
    public void onItemClick(AdapterView<?> parent, View view, 
      int position, long rowId) { 


     AlertDialog.Builder alert = new AlertDialog.Builder(
       SubMenu.this); 
       alert.setTitle("List"); 
       alert.setMessage(" selected Item is=" 
       +parent.getItemAtPosition(position)); 
       .setNeutralButton("OK", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dlg, int sumthin) { 
         // do whatever you want to do 
        } 
       }).show(); 

    } 
関連する問題