【问题标题】:Logcat Limitations or BugLogcat 限制或错误
【发布时间】:2015-07-03 23:37:45
【问题描述】:

我正在创建一个带有许多按钮的片段。部分出于懒惰,只是为了看看是否可能,我创建了几行代码来输出每个按钮 onclick 的必要代码。然而,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 个 id,但在 5 个的 R. 处停止。 此外,当 Log.i("Hi", "HEY") 被删除时,它不会打印出任何东西。 任何帮助弄清楚世界上正在发生的事情都将是一个很大的帮助。

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

【问题讨论】:

    标签: android android-fragments logcat android-logcat


    【解决方案1】:

    我认为您用于记录的标签太长了。它没有很好的文档记录,但它有 23 个字符的限制,并且没有保证当您超过它时日志记录会正常工作。

    The logging tag can be at most 23 characters

    【讨论】:

    • 是的,这就是最初的想法。但是我把标签放在文本编辑器中,它有 104 个字符,所以看起来这个限制不再是真的,但也许有一个新的限制。
    猜你喜欢
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多