2015-07-03 109 views
0

我正在用許多按鈕創建一個片段。部分出於懶惰,只是爲了看看是否可行,我已經創建了幾行代碼來輸出每個按鈕onclick的nessecary代碼。然而logcat一直在實現這一點上造成麻煩。Logcat限制或錯誤

代碼:

public class practiceFinishFragment extends Fragment implements View.OnClickListener { 

    String idss = ""; 
    TextView textView; 
    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View v = inflater.inflate(R.layout.practice_finished_fragment, container, false); 
     LinearLayout layout = (LinearLayout) v.findViewById(R.id.finishedLayout); 
     textView = (TextView) v.findViewById(R.id.textView3); 
for(int i = 0; layout.getChildCount() > i; i++){ 
      if(layout.getChildAt(i) instanceof Button){ 
       layout.getChildAt(i).setOnClickListener(this); 
       String ids = layout.getChildAt(i).getResources().getResourceEntryName(layout.getChildAt(i).getId()); 

idss = idss + "\n" + "case: "+ "R.id." +ids; 
       //Log.i(idss, ""); 
      } 
     } 
     Log.i(idss, ""); 
     textView.setText(idss); 

     return v; 
    } 

    @Override 
    public void onClick(View view) { 
     Log.i("HI", "Hey"); 
     switch (view.getId()){ 
     case R.id.playAgain: 
      Log.i(idss, ""); 
      // Log.i("HI", "He"); 
      //case 

     } 

    } 
} 

XML

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_horizontal" 
android:id="@+id/finishedLayout" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textSize="32sp" 
     android:layout_marginTop="50dp" 
     android:text="Good Job You Got \n X out of Y \n Questions Correct" 
     android:gravity="center" 
     android:id="@+id/textView3" 
     android:layout_gravity="center" 

     /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Play Again" 
     android:id="@+id/playAgain" 
     /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Return to Start" 
     android:id="@+id/returnStart" 
     /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Share Your Score" 
     android:id="@+id/shareScore" 
     /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Go over Missed" 
     android:id="@+id/retry" 
     /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Review Statistics" 
     android:id="@+id/scoreStatistics" 
     /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Change Preferences" 
     android:id="@+id/changePrefrences" 
     /> 

</LinearLayout> 

它返回第一4個IDS但在的5 的R.停止而且,當Log.i( 「您好」,「嘿「)被刪除它不會打印出任何東西。 任何幫助搞清楚世界上正在發生什麼,這將是一個很大的幫助。

case: R.id.playAgain 
    case: R.id.returnStart 
    case: R.id.shareScore 
    case: R.id.retry 
    case: R. at[ 07-03 19:31:14.715 755: 867 E/WifiStateMachine ] 
    [1,435,966,274,715 ms] noteScanEnd WorkSource{10011} onTime=0 

回答

1

我認爲您用於記錄的標記太長。它沒有很好的記錄,但它有23個字符的限制,沒有保證日誌記錄將超過它時正常工作。

The logging tag can be at most 23 characters

+0

是的,這是最初的想法。不過,我把標籤放在一個文本編輯器中,它有104個字符,所以看起來好像這個限制不再是真的,但是可能有一個新的限制。 –