2012-05-03 2 views
1

사용자가 EditText 상자에 검색 매개 변수를 입력하고 가장 가까운 대상을 쿼리 할 수있는 Android 매핑 앱에서 작업하고 있습니다. MapView에 핀으로 그려져있다.Android : 메인 활동 내에서 SlidingDrawer (또는 작은 목록)를 동적으로 채우기

핀을 클릭하면 위치 정보가 표시되지만 사용자에게 더 많은 정보를 제공하고 싶습니다. SlidingDrawer가 채워져 목적지/거리의 이름을 사용자에게 보여줄 수 있다고 생각했습니다.

많은 시간을 들여서 많은 책을 읽고 거의 진전되지 않은 지금 나는 지역 사회에 도움을 요청하고 있습니다.

내가 겪고있는 문제는 주 활동 내에서 SlidingDrawer의 내용을 채우는 방법을 알 수 없다는 것입니다. 새로운 액티비티를 시작할 수는 있지만 MapView가 화면에서 사라집니다. SlidingDrawer뿐만 아니라지도를 볼 수 있어야합니다. 그리고 SlidingDrawer를 Activity로 설정하지 않고 채우는 방법을 알아낼 수 없습니다.

(또한 대상 목록이 포함 된 SlidingDrawer 일 필요는 없습니다.) 레이아웃을 수정하여 작은 (최대 3 개 항목) 목록을 만들고지도의 일부를 제거 할 수 있습니다. 부동산은 쉽게 경우지만, 나도 그렇게하는 방법을 잘 모르겠어요) 여기

내 SlidingDrawer 호출하는 코드이다. 이것은 내 SlidingDrawer 클래스의 코드가

  //call SlidingDrawer 
     Intent drawerIntent = new Intent(this, SlidingDrawerFinal.class); 
     drawerIntent.putExtra("lat", lat); 
     drawerIntent.putExtra("lon", lon); 
     int numberOfTargetsForList = numberOfLoops; 
     drawerIntent.putExtra("numberOfTargetsForList", numberOfTargetsForList); 
     for(int i = 0; i < target.length; i++){ 
      drawerIntent.putExtra("target" + Integer.toString(i), target[i]); 
     } 
     this.startActivity(drawerIntent); 

(extends Activity) : 서랍 안의 목록을 채우는 :

View inflatedDrawerLayout = getLayoutInflater().inflate(R.layout.drawer_main, null); 
    int width = getWindow().getAttributes().width; 
    int height = 300; 
    LayoutParams params = new LayoutParams(width, height); 
    getWindow().addContentView(inflatedDrawerLayout, params); 

    // add some data 
      ArrayList<MyData> myDataList = new ArrayList<MyData>(); 
      myData = new MyData[numberOfTargets]; 

      for(int i = 0; i < numberOfTargets; i++){ 
       String lineTwo = ""; 
       if(target[i].getRating().equals("Not Yet Rated")){ 
        lineTwo = "  " + target[i].getRating() + "       " + 
          Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles"; 
       } 
       else{ 
        lineTwo = "  rating: " + target[i].getRating() + "/5 stars     " + 
          Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles"; 
       } 
       String lineOne = (Integer.toString(i + 1) + ": " + target[i].getName() + ", " + target[i].getVicinity()) + "\n" + lineTwo; 
       myData[i] = new MyData(lineOne, i); 
       myDataList.add(myData[i]); 

      }     

      mListView = (ListView) findViewById(R.id.listview_); 

      mListView.setAdapter(new MyListAdapter(this, R.layout.drawer_row, myDataList)); 
      drawer = (SlidingDrawer) findViewById(R.id.drawer); 
      handleButton = (Button) findViewById(R.id.handle); 
      drawer.animateOpen(); 

      drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() { 

      public void onDrawerOpened() { 
        handleButton.setBackgroundResource(R.drawable.handle_down_white); 
       } 
      }); 

내 레이아웃 파일 :

main.xml에 :

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dip"> 
     <EditText 
      android:id="@+id/geocode_input" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/placeName" 
      android:inputType="text" 
      android:lines="1" />  
     <Button 
      android:id="@+id/geocode_button" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/goLabel" /> 
    </LinearLayout> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" >   
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 
     <view android:id="@+id/mv" 
      class="com.google.android.maps.MapView" 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:clickable="true" 
      android:apiKey="my_API_Key"/> 
    </LinearLayout> 
    <include layout="@layout/drawer_main"/> 
    </FrameLayout> 
</LinearLayout> 

하고, 마지막으로, drawer_main.xml이 너무 긴 것을

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
    <SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/drawer" 
     android:handle="@+id/handle" 
     android:content="@+id/content" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@null" 

     android:layout_gravity="bottom"> 

      <LinearLayout 
       android:id="@id/content" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 

        <TextView 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:textSize="14dip" 
         android:textStyle="bold|italic" 
         android:background="@android:color/white" 
         android:textColor="@android:color/black" 
         android:text="@string/top_search_results" > 
        </TextView> 

        <View 
         android:background="@android:drawable/divider_horizontal_bright" 
         android:layout_width="fill_parent" 
         android:layout_height="2dp" > 
        </View> 

        <ListView 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/listview_" 
         android:background="@android:color/black" 
         android:textColor="@android:color/white" 
         android:divider="@android:color/transparent" 
         android:dividerHeight="2dp" > 
        </ListView> 

      </LinearLayout> 

      <Button 
       android:id="@id/handle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/handle_down_white"> 
      </Button> 

    </SlidingDrawer> 
</FrameLayout> 

죄송합니다. 어떤 도움이라도 대단히 감사하겠습니다.

답변

0

내가 선택한 해결책은 프로그래밍 방식으로는 이상적이지 않지만 레이아웃은 잘 작동합니다. 3 가지 이상의 결과가 없다는 것을 알았으므로 검색 막대 아래에 3 개의 작은 TextView를 포함하도록 레이아웃을 변경했으며 (슬프게도) SlidingDrawer를 모두 제거했습니다. 결과가 돌아 오면 필요한만큼 TextViews를 채 웁니다. 각 TextViews에는 onClickListener가 있습니다. 확장 성이 좋지 않으며 모든 것이 하드 코딩됩니다. 그러나 그것은 효과적이다. 안드로이드에 대해 더 많이 배우면서이 솔루션을 개선하려고 노력할 것입니다.

새로운 레이아웃 :

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dip"> 


     <EditText 
      android:id="@+id/geocode_input" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/placeName" 
      android:inputType="text" 
      android:lines="1" /> 

     <Button 
      android:id="@+id/geocode_button" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/goLabel" /> 

    </LinearLayout> 

    <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="13dip" 
      android:textStyle="bold|italic" 
      android:background="@android:color/black" 
      android:textColor="@android:color/white" 
      android:id="@+id/search_results_header" > 
    </TextView> 

    <View android:id="@+id/bar_over_one"  
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="#DADADA" /> 

    <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="11dip" 
      android:background="@android:color/black" 
      android:textColor="@android:color/white" 
      android:id="@+id/line_one" > 
    </TextView> 

    <View android:id="@+id/bar_over_two"  
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="#DADADA" /> 

    <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="11dip" 
      android:background="@android:color/black" 
      android:textColor="@android:color/white" 
      android:id="@+id/line_two" > 
    </TextView> 

    <View android:id="@+id/bar_over_three"  
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="#DADADA" /> 

    <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="11dip" 
      android:background="@android:color/black" 
      android:textColor="@android:color/white" 
      android:id="@+id/line_three" > 
    </TextView> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 
     <view android:id="@+id/mv" 
      class="com.google.android.maps.MapView" 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:clickable="true" 
      android:apiKey="0fmGmyFrFDUrPGrwXR_scZZxVx6CkSdK-sys-Qw"/> 
    </LinearLayout> 
</LinearLayout> 

새로운 코드 :

private void populateList(int numberOfTargetsForList){ 
    TextView header = (TextView) findViewById(R.id.search_results_header); 
    header.setText("Top Search Results"); 

    int i = 0; 
    //first line in list 
    barOverOne.setVisibility(View.VISIBLE); 
    String ratingAndDistance = ""; 
    if(target[i].getRating().equals("Not Yet Rated")){ 
     ratingAndDistance = "  " + target[i].getRating() + "       " + 
       Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles"; 
    } 
    else{ 
     ratingAndDistance = "  rating: " + target[i].getRating() + "/5 stars     " + 
       Double.toString((Math.round(target[i].getDistance()*100.0))/100.0) + " miles"; 
    } 
    String detailsForLineOne = (Integer.toString(i + 1) + ": " + target[i].getName() + ", " + target[i].getVicinity()) + "\n" + ratingAndDistance; 
    TextView lineOne = (TextView) findViewById(R.id.line_one); 
    lineOne.setText(detailsForLineOne); 
    lineOne.setOnClickListener(this); 

    i++; 

...(유사한 블록 = 1 I의 경우를 처리하고 I = 2)

마지막 내 온 클릭() 방법 :

case R.id.line_one:{ 
    String locForURL = "origin=" + Double.toString(lat/1000000.0) + 
      "," + Double.toString(lon/1000000.0) + "&destination=" + 
      Double.toString(target[0].getLat()/1000000.0) + "," + 
      Double.toString(target[0].getLon()/1000000.0); 
    Intent intent = new Intent(this, ParsingXMLDirectionsWithListView.class); 
     intent.putExtra("dirTitle", target[0].getName()+ " (" + 
      Double.toString((Math.round(target[0].getDistance()*100.0))/100.0) + " miles)"); 
     intent.putExtra("locForURL", locForURL); 
    this.startActivity(intent); 
    break; 
}//line_one 

...

(라인 둘, 셋 유사한 블록) 완벽하지는 않지만 오. 최소한 사용자의 입장에서 보면 꽤 좋았습니다. SlidingDrawer 경로를 계속 따라 가면서 마감 시간을 맞추지 못했습니다. 어쩌면 내가 좀 더 자유 시간을 가질 때 내가 알아낼 수 있는지 알게 될거야 ....

+0

누구든지 내 원래 질문에 대한 명확한 대답을 가지고 있다면, 나는 여전히 그것을 듣고 싶습니다. SlidingDrawer를 주요 활동 내에서 동적으로 채울 수 있습니까? – pjd

0

팝업 창을 사용할 수 있습니다.

View popupView = layoutInflater.inflate(R.layout.popup_window, null); 

    final PopupWindow popupWindow = new PopupWindow(popupView, 
      LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

    ImageButton btnCancel = (ImageButton) popupView 
      .findViewById(R.id.btnCancel); 


popupWindow.showAtLocation(LayoutView, Gravity.BOTTOM 
      | Gravity.CENTER_HORIZONTAL, (LayoutView.getWidth() - popupView 
      .getWidth())/2, LayoutView.getHeight() 
      - popupWindow.getHeight() - 10); 
    popupWindow.setAnimationStyle(Animation.RELATIVE_TO_SELF); 
    popupWindow.setFocusable(true); 
    popupWindow.update(); 
+0

초고속 응답에 감사드립니다. PopupWindow의 문제점은 마치 PopupWindow가 해제 된 후에 다시 호출 할 수 없다는 것입니다. 사용자는 주어진 시간에 목록과지도를 모두 참조 할 수 있어야합니다. 그래도 좋은 생각. 노력해 주셔서 감사합니다. – pjd

+0

버튼을 클릭 할 때 클릭 한 번으로 전화하십시오. –

+0

그 부분을 살펴 보겠습니다. 감사. 다른 방향으로 향하기 전에 다른 누구나 내 SlidingDrawer에 대한 생각을 가지고 있습니까? – pjd