2011-04-28 3 views
0

샘플을 SD로 저장할 수있는 어구가 있습니다. 나는 버튼 어댑터 장소에서 다음 코드로 설정된 GRIDVIEW를 사용 : 나는 샘플을 저장하는 위치의 옵션을 제공, 길게 누르면 여기에 상황에 맞는 메뉴를 통합 찾고Gridview Button Adapter 컨텍스트 메뉴

public View getView(int position, View convertView, ViewGroup parent) { 
    try { 
     final Sample sample = board.getSamples().get(position); 

     if (sample != null) { 

      Button button = new Button(context); 
      button.setText(sample.getName()); 
      button.setTextColor(Color.WHITE); 
      button.setTextSize(12); 
      button.setOnClickListener(new OnClickListener() { 

       public void onClick(View v) { 
        context.play(sample); 
       } 

      }); 

      // TODO Implement this correctly. 
      button.setOnLongClickListener(new OnLongClickListener() { 
      public boolean onLongClick(View v) { 

      return context.saveToSD(sample); 


      } 
      }); 

      return button; 
     } 
    } catch (IndexOutOfBoundsException e) { 
     Log.e(getClass().getCanonicalName(), "No sample at position " 
       + position); 
    } 

    return null; 
} 

. 이 메서드 내에서 컨텍스트 메뉴에 대한 버튼을 등록 할 수없는 것 같습니다 (예 : registerForContextMenu (button)). 오류가 발생하므로

나는 약간의 어려움을 겪었습니다. 어떤 포인터가 큰 도움이 될 것입니다. .

감사

이 이전 게시물입니다하지만 동일한 주제에 대한 답을 찾고 있었다 나는 오늘 그것을 건너 온 것을 내가 그것을 가지고

답변

0

는. 여기에 질문처럼 나는 항목의 그리드를 가지고 싶었 긴 클릭시 컨텍스트 메뉴를 표시하십시오.

컨텍스트 메뉴를 사용하고 있지 않지만 대신 AlertDialog를 사용하고 있습니다.

gridview.setOnItemLongClickListener(new OnItemLongClickListener() { 
     public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) 
     { 
      showOptionsMenu(position); 
      return true; 
     } 

    }); 

public void showOptionsMenu(int position) 
{ 
    new AlertDialog.Builder(this) 
    .setTitle("test").setCancelable(true).setItems(R.array.myOptions, 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialoginterface, int i) { 
         //take actions here according to what the user has selected 
        } 
      } 
    ) 
.show(); 
} 

희망이 있습니다.