1

다음 코드에서 옵션 메뉴가 있는데 메뉴 옵션을 선택하면 텍스트 뷰를 업데이트하려고합니다. 텍스트를 처음 설정하면 정상적으로 작동하며 오류가 생성되지 않습니다. settext가 작동하지 않는 코드는 다음과 같습니다. 디버그 문을 넣었지만 코드가 업데이트되고 있지만 텍스트는 업데이트되지 않습니다. 업데이트하지 않는 코드 옆에 화살표를 놓습니다. 다른 textview 예제를 검토하십시오. 그러나 알아낼 수는 없습니다. 여기 TextView가 변경되지 않음

public class ChapterListFragment extends ListFragment { 
private static final boolean VERBOSE = true; 
private ArrayList<Chapters> mChapters; 
private static final String TAG = "ChapterListFragment"; 
private static final int BFLAT = 1; 
private static final int EFLAT = 2; 

private TextView mChapterSelected; 
private View mView; 
private int mKeySelected; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    if (VERBOSE) Log.v(TAG, "+++ onCreate +++"); 
    super.onCreate(savedInstanceState); 
    // Must explicitly tell Fragment Manager that the fragment should receive a call to 
    // onCreateOptionsMenu(). 
    setHasOptionsMenu(true); 

    // Get the view for the Fields 
    if (mView == null) { 
     mView = getActivity().getLayoutInflater() 
       .inflate(R.layout.activity_improvisation, null); 
    } 

    getActivity().setTitle(R.string.chapters_title); 
    mChapters = ChapterList.get(getActivity()).getChapters(); 

    ChapterAdapter adapter = new ChapterAdapter(mChapters); 
    setListAdapter(adapter);   

    mChapterSelected = (TextView) mView.findViewById(R.id.chapter_selected); 
    mChapterSelected.setText("Chapter Selected Here");   
} 

@Override 
public void onListItemClick(ListView l, View v, int position, long id) {    
    // Get the chapter from the adapter 
    Chapters c = ((ChapterAdapter)getListAdapter()).getItem(position); 

    //Start ImprovisationActivity 
    Intent i = new Intent(getActivity(), ImprovisationActivity.class); 
    i.putExtra(ChapterFragment.EXTRA_CHAPTER_ID, c.getId()); 
    i.putExtra(ChapterFragment.EXTRA_KEYSELECTED, mKeySelected); 
    startActivity(i); 
} 


@Override 
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
    super.onCreateOptionsMenu(menu, inflater); 
    inflater.inflate(R.menu.fragment_chapters_list, menu); 
} 

내가 나오지 않았어 왜 발견하지 않은 XML 파일

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<LinearLayout 
    android:layout_weight="2" 
    android:layout_height="fill_parent" 
    android:layout_width="match_parent" 
    > 
<VideoView 
    android:id="@+id/video_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    /> 
</LinearLayout> 

<LinearLayout 
    android:layout_weight="1" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    android:orientation="vertical" > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/chapter_selected" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity = "center" 
      android:textStyle="bold" 
      android:paddingLeft="4dp" 
      android:paddingRight="4dp" 
      android:text="Chapter Selection" 
    />      

    </LinearLayout> 

<FrameLayout 
      android:id="@+id/fragmentContainer" 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      /> 
</LinearLayout> 

+0

앱은 정상적으로 계속 진행됩니다. 오류 메시지, 동결 없음 등 ...? – codeMagic

+0

@codeMagic 예, 앱은 정상적으로 계속됩니다. 오류 또는 동결 없음. textview에 포커스가 없거나 업데이트 할 수 없다고 가정합니다. 파편을 다룰 때 textviews를 업데이트하는 것이 어렵다는 것을 알았습니다. 사용자가 어떤 메뉴 옵션을 선택했는지 알 필요가 있습니다. 아마도 그렇게하는 것이 더 좋은 방법 일 것입니다. – sowens

+0

나는 당신이하고있는 일을 정확하게 모르지만 토스트만으로 충분할 것인가? – codeMagic

답변

0

입니다 : 필요한 경우 여기

 @Override 
public boolean onOptionsItemSelected(MenuItem item) { 

    switch (item.getItemId()) { 
     case R.id.menu_item_Bflat: 
      if (VERBOSE) Log.v(TAG, "+++ menu_item_Bflat +++"); 
      // BFLAT = 1 
      mKeySelected = BFLAT; 
    >>>>  mChapterSelected.setText("B Flat"); 
      return true; 
     case R.id.menu_item_Eflat: 
      // EFLAT = 2 
      mKeySelected = EFLAT; 
    >>>>  mChapterSelected.setText("E Flat"); 
      return true; 
     default: 
      return super.onOptionsItemSelected(item); 
    } // switch 
} // onOptionsItemSelected 

는, 내 코드의 나머지 부분입니다 setText는 아니지만 사용자가 메뉴 항목을 선택한 후 자막을 표시하면 내 용도로 적합합니다.