2016-12-26 13 views
-1

나는 초보자입니다. 하나의 목록보기가 있습니다. 목록에서 항목을 클릭하면 피드로 사용할 수있는 알림 대화 상자가 열립니다. 너무 많은 단추, 회 전자, 텍스트 등을 편집 할 수 있으므로 작업으로 결정했습니다. .listview Item을 클릭하면 경고 대화 상자와 비슷한 내 활동을 어떻게 열 수 있습니까?

지금은 x32 파일을 만들었는지 여부는 작동 여부를 확인하기 위해 & 그 코딩을 할 것입니다. 이제 내 질문은 어떻게 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는 위에서 볼 수 있듯이 나는 팝업을 사용하여 시도하지만, u는 클릭이나 버튼을 선택하면 thts가 작동하지 않는 등 여기

내 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

을 사용 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 안에 넣고 두 번째 자식을 일종의 레이아웃 (예 : RelativeLayout)으로 스크롤보기의 맨 위로 이동하십시오. 프레임 레이아웃은 두 번째 자식을 첫 번째 자식 앞에 배치합니다. 기본적으로 두 번째 자식 표시 설정 : 사라지고 목록보기에 클릭이있을 때 그를 보이게 만들고, 부모와 크기를 일치시키는 부모를 만들고 마진을 추가하여 뒤에있는 것을 볼 수 있습니다.

예 : 활동을

<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

알리미에서 스피너, chbox 등은 모두 대화 상자에서 제대로 작동합니까? –

+0

분명히, 레이아웃을 만들고, LayoutInflater를 사용하여 Layout을 inflate하고, AlertDialogBuilder에 필요한 메소드를 작성하면됩니다. –

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

    }