I am creating a fragment with many buttons. Partially out of laziness and just to see if it is possible, I have created a several lines of code to output the nessecary code for each buttons onclick. However the logcat has been causing trouble in achieving this.
code:
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>
It returns the first 4 ids but stops at the R. of the 5. Also when the Log.i("Hi", "HEY") is removed it wont print out anything. Any help figuring out what in the world is going on in this would be a great help.
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